VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmDataEnv 
   BackColor       =   &H00E0E0E0&
   Caption         =   $"fongvNPS.frx":0000
   ClientHeight    =   8820
   ClientLeft      =   945
   ClientTop       =   1035
   ClientWidth     =   15060
   ForeColor       =   &H80000017&
   Icon            =   "fongvNPS.frx":0087
   LinkTopic       =   "Form1"
   ScaleHeight     =   8820
   ScaleMode       =   0  'User
   ScaleWidth      =   15060
   Begin VB.Frame Frame3 
      Caption         =   "МОДЕМ"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   9.75
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1455
      Left            =   9000
      TabIndex        =   4
      Top             =   120
      Width           =   2115
      Begin VB.ComboBox ATC 
         Height          =   315
         Left            =   720
         Style           =   2  'Dropdown List
         TabIndex        =   8
         Top             =   840
         Width           =   1340
      End
      Begin VB.ComboBox cboPort 
         Height          =   315
         ItemData        =   "fongvNPS.frx":04C9
         Left            =   720
         List            =   "fongvNPS.frx":04CB
         Style           =   2  'Dropdown List
         TabIndex        =   5
         Top             =   360
         Width           =   1305
      End
      Begin MSCommLib.MSComm MSComm1 
         Left            =   960
         Top             =   1200
         _ExtentX        =   1005
         _ExtentY        =   1005
         _Version        =   393216
         CommPort        =   2
         DTREnable       =   -1  'True
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         Caption         =   "АТС:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   204
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   1
         Left            =   120
         TabIndex        =   7
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         Caption         =   "ПОРТ:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   204
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Index           =   0
         Left            =   120
         TabIndex        =   6
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Набрать номер"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000C0&
      Height          =   1455
      Left            =   6000
      TabIndex        =   1
      Top             =   120
      Width           =   2895
      Begin VB.TextBox Text1 
         Alignment       =   2  'Center
         DataField       =   "N_tel"
         DataSource      =   "Data1"
         Height          =   285
         Left            =   1560
         TabIndex        =   3
         Top             =   1080
         Visible         =   0   'False
         Width           =   1095
      End
      Begin VB.TextBox Text2_p 
         Alignment       =   2  'Center
         DataField       =   "Predpr"
         DataSource      =   "Data2"
         Height          =   285
         Left            =   1560
         TabIndex        =   14
         Top             =   1080
         Visible         =   0   'False
         Width           =   735
      End
      Begin VB.TextBox Text1_p 
         DataField       =   "N_tel"
         DataSource      =   "Data2"
         Height          =   285
         Left            =   120
         TabIndex        =   13
         Top             =   1080
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Отмена"
         Height          =   375
         Left            =   1200
         TabIndex        =   10
         Top             =   240
         Visible         =   0   'False
         Width           =   735
      End
      Begin VB.TextBox Text2 
         DataField       =   "Family"
         DataSource      =   "Data1"
         Height          =   285
         Left            =   120
         TabIndex        =   12
         Top             =   1080
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.ComboBox Commy 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         ItemData        =   "fongvNPS.frx":04CD
         Left            =   120
         List            =   "fongvNPS.frx":04CF
         Sorted          =   -1  'True
         TabIndex        =   11
         Text            =   "Commy"
         Top             =   720
         Width           =   2655
      End
      Begin VB.CommandButton Command2 
         DownPicture     =   "fongvNPS.frx":04D1
         Height          =   375
         Left            =   2040
         Picture         =   "fongvNPS.frx":0913
         Style           =   1  'Graphical
         TabIndex        =   2
         Top             =   240
         Width           =   615
      End
      Begin VB.Label Label8 
         Caption         =   "Журнал звон:"
         Height          =   255
         Left            =   120
         TabIndex        =   19
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Status 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Height          =   315
         Left            =   120
         TabIndex        =   9
         Top             =   1080
         Width           =   2655
      End
   End
   Begin VB.Timer Timer1 
      Interval        =   300
      Left            =   8640
      Top             =   0
   End
   Begin VB.Frame Frame1 
      Caption         =   "Поиск в справочнике "
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1455
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5730
      Begin VB.Frame Frame5 
         BackColor       =   &H8000000A&
         BorderStyle     =   0  'None
         Height          =   615
         Index           =   2
         Left            =   1080
         TabIndex        =   45
         Top             =   240
         Visible         =   0   'False
         Width           =   2715
         Begin VB.Data Data3 
            Caption         =   "Data3"
            Connect         =   "Access"
            DatabaseName    =   "fonmy.mdb"
            DefaultCursorType=   0  'DefaultCursor
            DefaultType     =   2  'UseODBC
            EOFAction       =   2  'Add New
            Exclusive       =   0   'False
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   12
               Charset         =   204
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   0
            Options         =   0
            ReadOnly        =   0   'False
            RecordsetType   =   1  'Dynaset
            RecordSource    =   "MY"
            Top             =   0
            Width           =   2655
         End
      End
      Begin VB.Frame Frame5 
         BackColor       =   &H8000000A&
         BorderStyle     =   0  'None
         Height          =   615
         Index           =   1
         Left            =   1080
         TabIndex        =   44
         Top             =   240
         Visible         =   0   'False
         Width           =   2715
         Begin VB.Data Data2 
            Caption         =   "Data2"
            Connect         =   "Access"
            DatabaseName    =   "fon.mdb"
            DefaultCursorType=   0  'DefaultCursor
            DefaultType     =   2  'UseODBC
            Exclusive       =   0   'False
            Height          =   495
            Left            =   0
            Options         =   0
            ReadOnly        =   0   'False
            RecordsetType   =   1  'Dynaset
            RecordSource    =   "PREDPR"
            Top             =   0
            Width           =   2685
         End
      End
      Begin VB.Frame Frame5 
         BackColor       =   &H8000000A&
         BorderStyle     =   0  'None
         Height          =   615
         Index           =   0
         Left            =   1080
         TabIndex        =   43
         Top             =   240
         Width           =   2775
         Begin VB.Data Data1 
            Caption         =   "Data1"
            Connect         =   "Access"
            DatabaseName    =   "fon.mdb"
            DefaultCursorType=   0  'DefaultCursor
            DefaultType     =   2  'UseODBC
            Exclusive       =   0   'False
            Height          =   495
            Left            =   0
            Options         =   0
            ReadOnly        =   0   'False
            RecordsetType   =   1  'Dynaset
            RecordSource    =   "NASELEN"
            Top             =   0
            Width           =   2685
         End
      End
      Begin VB.Frame Frame6 
         BackColor       =   &H8000000A&
         BorderStyle     =   0  'None
         Height          =   495
         Left            =   4080
         TabIndex        =   41
         Top             =   360
         Width           =   1575
         Begin VB.Label Label7 
            Alignment       =   2  'Center
            Caption         =   "Label7"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   11.25
               Charset         =   204
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   0
            TabIndex        =   42
            Top             =   0
            Width           =   1455
         End
      End
      Begin VB.TextBox Tekv 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   5160
         TabIndex        =   38
         Top             =   1080
         Width           =   495
      End
      Begin VB.TextBox Tedom 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   4560
         TabIndex        =   37
         Top             =   1080
         Width           =   495
      End
      Begin VB.TextBox Testr 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   3000
         TabIndex        =   36
         Top             =   1080
         Width           =   1455
      End
      Begin VB.TextBox Tefio 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFC0&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   285
         Left            =   1200
         TabIndex        =   35
         ToolTipText     =   "Для записи образца используются буквы и  символы шаблона ( *, ?).  Где  * — соответствует цепочке букв, ? — одной букве"
         Top             =   1080
         Width           =   1695
      End
      Begin VB.TextBox Tent 
         Alignment       =   2  'Center
         BackColor       =   &H00C0E0FF&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000C0&
         Height          =   285
         Left            =   120
         TabIndex        =   34
         ToolTipText     =   "Для записи образца используются цифры и  символы шаблона ( *, ?).   * — соответствует цепочке цифр, ? — одной цифре"
         Top             =   1080
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Appearance      =   0  'Flat
         DownPicture     =   "fongvNPS.frx":0D55
         Enabled         =   0   'False
         Height          =   375
         Left            =   240
         Picture         =   "fongvNPS.frx":1197
         Style           =   1  'Graphical
         TabIndex        =   33
         ToolTipText     =   "Очистить условие"
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Ф И О "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Index           =   0
         Left            =   1800
         TabIndex        =   28
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label5 
         Alignment       =   2  'Center
         Caption         =   "Кв"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   5160
         TabIndex        =   32
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         Caption         =   "Дом"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4560
         TabIndex        =   31
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "Улица"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3480
         TabIndex        =   30
         Top             =   840
         Width           =   855
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Ф И О "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   2
         Left            =   1800
         TabIndex        =   27
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         Caption         =   "Номер"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   204
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000C0&
         Height          =   255
         Left            =   360
         TabIndex        =   26
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Предприятие"
         Height          =   255
         Index           =   1
         Left            =   1440
         TabIndex        =   29
         Top             =   840
         Visible         =   0   'False
         Width           =   1335
      End
   End
   Begin VB.Frame Frame4 
      Height          =   4095
      Index           =   0
      Left            =   240
      TabIndex        =   15
      Top             =   2640
      Width           =   9615
      Begin MSDBGrid.DBGrid DBGrid1 
         Bindings        =   "fongvNPS.frx":15D9
         Height          =   4125
         Left            =   0
         OleObjectBlob   =   "fongvNPS.frx":15ED
         TabIndex        =   23
         Top             =   0
         Width           =   9690
      End
   End
   Begin VB.Frame Frame4 
      Height          =   4095
      Index           =   1
      Left            =   240
      TabIndex        =   16
      Top             =   2640
      Width           =   9375
      Begin MSDBGrid.DBGrid DBGrid2 
         Bindings        =   "fongvNPS.frx":27E8
         Height          =   4005
         Left            =   0
         OleObjectBlob   =   "fongvNPS.frx":27FC
         TabIndex        =   18
         Top             =   120
         Width           =   9690
      End
   End
   Begin VB.Frame Frame4 
      Height          =   4095
      Index           =   2
      Left            =   240
      TabIndex        =   24
      Top             =   2520
      Width           =   9735
      Begin MSDBGrid.DBGrid DBGrid3 
         Bindings        =   "fongvNPS.frx":3BAB
         Height          =   3885
         Left            =   0
         OleObjectBlob   =   "fongvNPS.frx":3BBF
         TabIndex        =   25
         Top             =   120
         Width           =   9450
      End
   End
   Begin MSComctlLib.TabStrip TabStrip1 
      Height          =   6375
      Left            =   120
      TabIndex        =   17
      Top             =   1680
      Width           =   11055
      _ExtentX        =   19500
      _ExtentY        =   11245
      MultiRow        =   -1  'True
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   3
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "Население"
            Key             =   "K1"
            Object.Tag             =   "TagN"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "Предприятия"
            Key             =   "K2"
            Object.Tag             =   "TagP"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "Личный"
            Key             =   "K3"
            Object.Tag             =   "TagM"
            ImageVarType    =   2
         EndProperty
      EndProperty
      MousePointer    =   99
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      MouseIcon       =   "fongvNPS.frx":4DB6
   End
   Begin VB.PictureBox Picture3 
      DrawStyle       =   6  'Inside Solid
      Enabled         =   0   'False
      Height          =   2055
      Left            =   11160
      Picture         =   "fongvNPS.frx":50D0
      ScaleHeight     =   1995
      ScaleWidth      =   2835
      TabIndex        =   20
      Top             =   0
      Visible         =   0   'False
      Width           =   2895
   End
   Begin VB.PictureBox Picture1 
      Height          =   1935
      Left            =   11160
      Picture         =   "fongvNPS.frx":14570
      ScaleHeight     =   1875
      ScaleWidth      =   1515
      TabIndex        =   39
      Top             =   0
      Visible         =   0   'False
      Width           =   1575
   End
   Begin VB.TextBox Text1_m 
      DataField       =   "N_tel"
      DataSource      =   "Data3"
      Height          =   285
      Left            =   5400
      TabIndex        =   21
      Top             =   1080
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.TextBox Text2_m 
      Alignment       =   2  'Center
      DataField       =   "Family"
      DataSource      =   "Data3"
      Height          =   285
      Left            =   6840
      TabIndex        =   22
      Top             =   1080
      Visible         =   0   'False
      Width           =   735
   End
   Begin VB.PictureBox Picture2 
      DrawStyle       =   6  'Inside Solid
      Enabled         =   0   'False
      Height          =   2055
      Left            =   11160
      Picture         =   "fongvNPS.frx":1F141
      ScaleHeight     =   1995
      ScaleWidth      =   2835
      TabIndex        =   40
      Top             =   0
      Visible         =   0   'False
      Width           =   2895
   End
   Begin VB.Image Image1 
      Height          =   525
      Index           =   0
      Left            =   1560
      Picture         =   "fongvNPS.frx":2CCED
      Stretch         =   -1  'True
      Top             =   10320
      Width           =   9855
   End
   Begin VB.Menu mnuExit 
      Caption         =   "Выход"
   End
   Begin VB.Menu mnuSp1 
      Caption         =   " "
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "Помощь"
   End
   Begin VB.Menu mnuAbout 
      Caption         =   "О программе"
   End
End
Attribute VB_Name = "frmDataEnv"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit


DefInt A-Z

Private mintCurFrame As Integer ' Current Frame visible
' This flag is set when the user chooses Cancel.
Dim CancelFlag
Dim gotfo As Integer

Dim ztOr As Integer
Dim mztOr As Integer
Dim MyFl(100) As String

Dim Warr(1 To 3, 0 To 8) As Single


Sub LoadPropertySettings()
Dim i As Integer, Settings As String
Dim lin$, x3#
' Load Port Settings
Settings = MSComm1.Settings
Dim stW As String

For i = 1 To 16
    cboPort.AddItem "Com" & Trim$(Str$(i))
Next i
cboPort.ListIndex = MSComm1.CommPort - 1

ATC.AddItem "ВостГОКа"
ATC.AddItem "УкрТелеком"
ATC.ListIndex = 0
        
    Commy.AddItem "95474 Autor"
    Commy.AddItem "23830 Alfa-Servis"
    Commy.AddItem "25266 Alfa-Servis"
If Dir("fonmy.txt") <> "" Then
    Open "fonmy.txt" For Input As #1
               Line Input #1, lin$
               ATC.ListIndex = Val(Left(lin$, 1))
               Line Input #1, lin$
               x3 = Val(Left(lin$, 1)) - 1
               If x3 >= 0 Then
                cboPort.ListIndex = x3
               Else
                Frame2.Visible = False
                Frame3.Visible = False
               End If
x3 = 1
           While (x3 < 100) And Not EOF(1)
               Line Input #1, lin$
               Commy.AddItem lin$
               x3 = x3 + 1
           Wend
           Close #1
End If
           
    Commy.ListIndex = 0
    mintCurFrame = 1
    
    Warr(1, 0) = 900#
    Warr(1, 1) = 2800#
    Warr(1, 2) = 2400#
    Warr(1, 3) = 730#
    Warr(1, 4) = 520#
    Warr(1, 5) = 730#
    Warr(1, 6) = 520#
    Warr(3, 0) = 900#
    Warr(3, 1) = 2800#
    Warr(3, 2) = 2400#
    Warr(3, 3) = 730#
    Warr(3, 4) = 520#
    Warr(3, 5) = 730#
    Warr(3, 6) = 520#
    Warr(2, 0) = 3150#
    Warr(2, 1) = 680#
    Warr(2, 2) = 2130#
    Warr(2, 3) = 1630#
    Warr(2, 4) = 540#
    Warr(2, 5) = 345#
    Warr(2, 6) = 345#
    Warr(2, 7) = 45#

If Dir("WGridCol.txt") <> "" Then
    Open "WGridCol.txt" For Input As #2
        For x3 = 0 To 6
            Line Input #2, stW
            Warr(1, x3) = stW
        Next x3
        For x3 = 0 To 6
            Line Input #2, stW
            Warr(3, x3) = stW
        Next x3
        For x3 = 0 To 7
            Line Input #2, stW
            Warr(2, x3) = stW
        Next x3
    
           Close #2
End If

End Sub

Private Sub Command1_Click()

    Tent.Text = ""
    Tefio.Text = ""
    Testr.Text = ""
    Tedom.Text = ""
    Tekv.Text = ""

End Sub

Private Sub Command2_Click()
    
Dim DialString$, FromModem$, dummy, Number$, Nb$, Temp$
Dim NewPort As Integer
Dim ni As Integer, Ind As Integer, scom As String

' Initialize the Comm control.
    If MSComm1.PortOpen Then
        MSComm1.PortOpen = False
    End If
    MSComm1.InputLen = 0
    NewPort = cboPort.ListIndex + 1
    MSComm1.CommPort = NewPort          ' Set the new port number.

'Nb = Text1.Text
Nb = Left(Trim(Commy.Text), 5)

  If Left(Nb, 2) = "AT" Or Left(Nb, 2) = "at" Then
    ni = InStr(Commy.Text, ";")
    If ni > 0 Then
        DialString$ = Left(Commy.Text, ni) + vbCr
    Else
        DialString$ = Trim(Commy.Text) + ";" + vbCr
    End If
  Else
    If ATC.ListIndex = 0 Then
        If Left(Nb, 1) = "9" Then
            Number = ",," & Right(Nb, 4)
        Else
            Number = ",,9," & Left(Nb, 1) & "," & Right(Nb, 4)
        End If
    Else
        Number = ",," & Left(Nb, 1) & "," & Right(Nb, 4)
    End If

    ' AT is the Hayes compatible ATTENTION command and is required to send commands to the modem.
    ' DT means "Dial Tone." The Dial command uses touch tones, as opposed to pulse (DP = Dial Pulse).
    ' Numbers$ is the phone number being dialed.
    ' A semicolon tells the modem to return to command mode after dialing (important).
    ' A carriage return, vbCr, is required when sending commands to the modem.
    DialString$ = "ATDP" + Number$ + ";" + vbCr
  End If
    Command3.Visible = True

    ' Open the communications port.
    On Error Resume Next
    MSComm1.PortOpen = True
    If Err Then
       MsgBox "COM:" & NewPort & " не подключен. Выбрать другой СОМ."
        Command3.Visible = False
       Exit Sub
    End If
    
    Temp$ = Status.Caption
'    Status.Caption = "Набираем номер - " + Number$
    Status.Caption = DialString$
    ' Flush the input buffer.
    MSComm1.InBufferCount = 0
    
    ' Dial the number.
    MSComm1.Output = DialString$
        
    ni = 0
    Ind = 0
    scom = Commy.Text
    
    For Ind = 0 To Commy.ListCount - 1
        If Commy.List(Ind) = scom Then ni = 1
    Next
    If ni = 0 Then
        Commy.AddItem Commy.Text
    End If

    ' Wait for "OK" to come back from the modem.
    Do
       dummy = DoEvents()
       ' If there is data in the buffer, then read it.
       If MSComm1.InBufferCount Then
          FromModem$ = FromModem$ + MSComm1.Input
          ' Check for "OK".
          If InStr(FromModem$, "BUSY") Then
              Beep
             MsgBox "Занято, нажмите <Enter> или <OK>"
             Exit Do
         End If
         If InStr(FromModem$, "OK") Then
             ' Notify the user to pick up the phone.
             Beep
             MsgBox "Поднимите трубку и нажмите <Enter> или <OK>"
             Exit Do
          End If
       End If
        
       ' Did the user choose Cancel?
       If CancelFlag Then
          CancelFlag = False
          Exit Do
       End If
    Loop
    
    ' Disconnect the modem.
    MSComm1.Output = "ATH" + vbCr
    Status.Caption = Temp$

    ' Close the port.
    MSComm1.PortOpen = False
    Command3.Visible = False

End Sub

Private Sub Command3_Click()
       CancelFlag = True
End Sub

Private Sub Data1_Reposition()
  Data1.Caption = Data1.Recordset.AbsolutePosition + 1
  Commy.Text = Text1.Text & " " & Text2.Text
  Label7.Caption = "из " & Val(Data1.Recordset.RecordCount)
End Sub

Private Sub Data2_Reposition()
  Data2.Caption = Data2.Recordset.AbsolutePosition + 1
  Commy.Text = Text1_p.Text & " " & Text2_p.Text
  Label7.Caption = "из " & Val(Data2.Recordset.RecordCount)
End Sub
Private Sub Data3_Reposition()
  Data3.Caption = Data3.Recordset.AbsolutePosition + 1
  Commy.Text = Text1_m.Text & " " & Text2_m.Text
  Label7.Caption = "из " & Val(Data3.Recordset.RecordCount)
End Sub

'
'Private Sub DBGrid1_AfterDelete()
'  MsgBox "AfterDelete"
'End Sub
'
'Private Sub DBGrid1_AfterInsert()
'  MsgBox "AfterInsert"
'End Sub

'Private Sub DBGrid1_AfterUpdate()
'  MsgBox "AfterUpdate"
'End Sub

Private Sub DBGrid1_BeforeDelete(Cancel As Integer)
   If MsgBox("УДАЛИТЬ запись?", vbCritical + vbOKCancel, "Запрос на удаление") <> vbOK Then Cancel = True
End Sub

Private Sub DBGrid1_BeforeInsert(Cancel As Integer)
'  MsgBox "BeforeInsert"
   If MsgBox("ДОБАВИТЬ новую запись?", vbOKCancel, "Запрос на добавление") <> vbOK Then Cancel = True
End Sub

Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
'  MsgBox "BeforeUpdate"
'    On Error Resume Next
   If MsgBox("СОРАНИТЬ изменения в записи?", vbOKCancel, "Запрос на сохранение") <> vbOK Then
    DBGrid1.ReBind
    Cancel = True
   End If
End Sub

Private Sub DBGrid1_ButtonClick(ByVal ColIndex As Integer)
Dim ee
 ee = MsgBox("Колнка ? " & Str(ColIndex), , "Запрос на сохранение")
End Sub

Private Sub DBGrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
Dim prS As Single
Dim frmW As Single

If frmDataEnv.WindowState <> 1 Then
frmW = CSng(frmDataEnv.Width)

     prS = IIf(frmW > 8000, ((frmW - 8000) / 4000), 0)
     Warr(1, ColIndex) = CSng(DBGrid1.Columns(ColIndex).Width) / (1 + prS / 2)
End If
End Sub
Private Sub DBGrid2_BeforeDelete(Cancel As Integer)
   If MsgBox("УДАЛИТЬ запись?", vbCritical + vbOKCancel, "Запрос на удаление") <> vbOK Then Cancel = True
End Sub

Private Sub DBGrid2_BeforeInsert(Cancel As Integer)
'  MsgBox "BeforeInsert"
   If MsgBox("ДОБАВИТЬ новую запись?", vbOKCancel, "Запрос на добавление") <> vbOK Then Cancel = True
End Sub

Private Sub DBGrid2_BeforeUpdate(Cancel As Integer)
'  MsgBox "BeforeUpdate"
   If MsgBox("СОРАНИТЬ изменения в записи?", vbOKCancel, "Запрос на сохранение") <> vbOK Then
    Cancel = True
    DBGrid2.ReBind
   End If
End Sub

Private Sub DBGrid2_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
Dim prS As Single
Dim frmW As Single

If frmDataEnv.WindowState <> 1 Then
frmW = CSng(frmDataEnv.Width)

     prS = IIf(frmW > 8000, ((frmW - 8000) / 4000), 0)
     Warr(2, ColIndex) = CSng(DBGrid2.Columns(ColIndex).Width) / (1 + prS / 2)
End If
End Sub

Private Sub DBGrid2_DblClick()
On Error Resume Next

Dim Msg$, Style#, Response ', MyString$
Dim dn_tel$, dfamily$, dstreet$, dprim$, ddom$, dkvart$, ddom1$, dkvart1$

dn_tel = " "
dfamily = " "
dstreet = " "
ddom = " "
ddom1 = " "
dkvart = " "
dkvart1 = " "

dn_tel = Data2.Recordset!n_tel
dfamily = Data2.Recordset!PREDPR
dstreet = Data2.Recordset!street
dprim = Data2.Recordset!prim
ddom = Data2.Recordset!dom
ddom1 = Data2.Recordset!dom1
dkvart = Data2.Recordset!kvart
dkvart1 = Data2.Recordset!kvart1

Msg = "Вставить  <" & dn_tel & "  " & dfamily & ">  в МОЙ справочник?"
Style = vbYesNo

Response = MsgBox(Msg, Style)
If Response = vbYes Then   ' User chose Yes.
    
    Data3.Recordset.AddNew
    Data3.Recordset!n_tel = dn_tel
    Data3.Recordset!family = Trim(dfamily) & ", " & Trim(dprim)
    Data3.Recordset!street = dstreet
    Data3.Recordset!dom = ddom
    Data3.Recordset!dom1 = ddom1
    Data3.Recordset!kvart = dkvart
    Data3.Recordset!kvart1 = dkvart1
    Data3.Recordset.Update
    Data2.Recordset.MoveNext
    Data2.Recordset.MovePrevious
 
End If


End Sub

Private Sub DBGrid1_DblClick()
On Error Resume Next

Dim Msg$, Style#, Response ', MyString$
Dim dn_tel$, dfamily$, dstreet$, ddom$, ddom1$, dkvart$, dkvart1$

dn_tel = " "
dfamily = " "
dstreet = " "
ddom = " "
ddom1 = " "
dkvart = " "
dkvart1 = " "

dn_tel = Data1.Recordset!n_tel
dfamily = Data1.Recordset!family
dstreet = Data1.Recordset!street
ddom = Data1.Recordset!dom
ddom1 = Data1.Recordset!dom1
dkvart = Data1.Recordset!kvart
dkvart1 = Data1.Recordset!kvart1

Msg = "Вставить  <" & Data1.Recordset!n_tel & "  " & Data1.Recordset!family & ">  в МОЙ справочник?"
Style = vbYesNo

Response = MsgBox(Msg, Style)
If Response = vbYes Then   ' User chose Yes.
    
    Data3.Recordset.AddNew
    Data3.Recordset!n_tel = dn_tel
    Data3.Recordset!family = dfamily
    Data3.Recordset!street = dstreet
    Data3.Recordset!dom = ddom
    Data3.Recordset!kvart = dkvart
    Data3.Recordset!dom1 = ddom1
    Data3.Recordset!kvart1 = dkvart1
    Data3.Recordset.Update
 
 Data1.Recordset.MoveNext
 Data1.Recordset.MovePrevious
    
End If


End Sub

Private Sub DBGrid3_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
Dim prS As Single
Dim frmW As Single

If frmDataEnv.WindowState <> 1 Then
frmW = CSng(frmDataEnv.Width)
     prS = IIf(frmW > 8000, ((frmW - 8000) / 4000), 0)
     Warr(3, ColIndex) = CSng(DBGrid3.Columns(ColIndex).Width) / (1 + prS / 2)
End If
End Sub


Private Sub Form_Load()
Picture2.Visible = True
Picture1.Visible = False
Picture3.Visible = False
 
On Error Resume Next

MyFl(0) = Dir("*.jpg")
For mztOr = 0 To 99
   If MyFl(mztOr) = "" Then
    Exit For
   End If
   MyFl(mztOr + 1) = Dir ' Get next entry.
Next


ztOr = 0
LoadPropertySettings
gotfo = 1
    Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
    Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
    Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 9970)
    Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6990)
End Sub

Private Sub Form_Resize()      ' *******

Dim frmW As Single
Dim prp As Integer
Dim prS As Single

If frmDataEnv.WindowState <> 1 Then
frmW = CSng(frmDataEnv.Width)
Warr(1, 7) = frmDataEnv.Width
    If frmDataEnv.Height > 3595 Then
        TabStrip1.Height = frmDataEnv.Height - 1225
        Frame4(0).Height = frmDataEnv.Height - 1800
        Frame4(1).Height = frmDataEnv.Height - 1800
        Frame4(2).Height = frmDataEnv.Height - 1800
        DBGrid1.Height = frmDataEnv.Height - 2500
        DBGrid2.Height = frmDataEnv.Height - 2500
        DBGrid3.Height = frmDataEnv.Height - 2500
    End If
    
    If frmW < 4500 Then
        TabStrip1.Width = 4000 - 50
        Frame4(0).Width = 4500 - 290
        Frame4(1).Width = 4500 - 290
        Frame4(2).Width = 4500 - 290
        DBGrid1.Width = 4500 - 340
        DBGrid2.Width = 4500 - 340
        DBGrid3.Width = 4500 - 340
        Image1(0).Width = 4500
    Else
        TabStrip1.Width = frmW - 50
        Frame4(0).Width = frmW - 290
        Frame4(1).Width = frmW - 290
        Frame4(2).Width = frmW - 290
        DBGrid1.Width = frmW - 340
        DBGrid2.Width = frmW - 340
        DBGrid3.Width = frmW - 340
        Image1(0).Width = frmW
    End If
    
    prp = 9500
 ' какую картинку размерить:
'    If Frame2.Visible Then
    If Frame5(0).Visible = True Then
        If frmW - Picture2.Width - prp + 550 > 0 Then
            Picture2.Left = (100 + prp + frmW - Picture2.Width) / 2
            Picture2.Visible = True
        ElseIf frmW - prp > 0 Then
            Picture2.Left = frmW - Picture2.Width
            Picture2.Visible = False
        Else
            Picture2.Left = prp - Picture2.Width
            Picture2.Visible = False
        End If
    Else
        If frmW - prp > 0 Then
            Picture2.Left = prp - Picture2.Width + (frmW - prp) / 2
        Else
            Picture2.Left = prp - Picture2.Width
        End If
   End If
   '===
    If Frame5(1).Visible = True Then
           If frmW - Picture3.Width - prp + 550 > 0 Then
            Picture3.Left = (100 + prp + frmW - Picture3.Width) / 2
            Picture3.Visible = True
        ElseIf frmW - prp > 0 Then
            Picture3.Left = frmW - Picture3.Width
            Picture3.Visible = False
        Else
            Picture3.Left = prp - Picture3.Width
            Picture3.Visible = False
        End If
    Else
        If frmW - prp > 0 Then
            Picture3.Left = prp - Picture3.Width + (frmW - prp) / 2
        Else
            Picture3.Left = prp - Picture3.Width
        End If
   End If
   '===
    If Frame5(2).Visible = True Then
           If frmW - Picture1.Width - prp + 550 > 0 Then
            Picture1.Left = (100 + prp + frmW - Picture1.Width) / 2
            Picture1.Visible = True
        ElseIf frmW - prp > 0 Then
            Picture1.Left = frmW - Picture1.Width
            Picture1.Visible = False
        Else
            Picture1.Left = prp - Picture1.Width
            Picture1.Visible = False
        End If
    Else
        If frmW - prp > 0 Then
            Picture1.Left = prp - Picture1.Width + (frmW - prp) / 2
        Else
            Picture1.Left = prp - Picture1.Width
        End If
   End If
   '===
   
   
    
        prS = IIf(frmW > 8000, ((frmW - 8000) / 4000), 0)
        For prp = 0 To 6
            DBGrid1.Columns(prp).Width = Warr(1, prp) * (1 + prS / 2)  '900
            DBGrid3.Columns(prp).Width = Warr(3, prp) * (1 + prS / 2)  '900
            DBGrid2.Columns(prp).Width = Warr(2, prp) * (1 + prS / 2)  '900
        Next prp
        
        DBGrid2.Columns(7).Width = Warr(2, 7) * (1 + prS / 2)   '900
    
    
    If frmW > 14000 Then
        DBGrid1.Font.Size = 18
        DBGrid3.Font.Size = 18
        DBGrid2.Font.Size = 14
    ElseIf frmW > 11900 Then
        DBGrid1.Font.Size = 14
        DBGrid3.Font.Size = 14
        DBGrid2.Font.Size = 12
    Else
        DBGrid1.Font.Size = 12
        DBGrid3.Font.Size = 12
        DBGrid2.Font.Size = 8
    End If
    DBGrid1.ReBind
    DBGrid2.ReBind
    DBGrid3.ReBind
End If



End Sub


Private Sub Form_Unload(Cancel As Integer)
Dim x3 As Integer
    
    Open "WGridCol.txt" For Output As #3
        For x3 = 0 To 6
            Write #3, Int(Warr(1, x3))
        Next x3
        For x3 = 0 To 6
            Write #3, Int(Warr(3, x3))
        Next x3
        For x3 = 0 To 7
            Write #3, Int(Warr(2, x3))
        Next x3
            Write #3, Int(Warr(1, 7))
            Write #3, 0
   
           Close #3
    
    If Me.WindowState <> vbMinimized Then
        SaveSetting App.Title, "Settings", "MainLeft", Me.Left
        SaveSetting App.Title, "Settings", "MainTop", Me.Top
        SaveSetting App.Title, "Settings", "MainWidth", Me.Width
        SaveSetting App.Title, "Settings", "MainHeight", Me.Height
    End If




'   Dim dbsNorthwind As Database
'
'   Set dbsNorthwind = OpenDatabase("fonmy.mdb")
'
'   ' Show the properties of the original database.
'   With dbsNorthwind
'      Debug.Print .Name & ", version " & .Version
'      Debug.Print "  CollatingOrder = " & .CollatingOrder
'      .Close
'   End With

   ' Make sure there isn't already a file with the
   ' name of the compacted database.
'   If Dir("fonmyr.mdb") <> "" Then _
'      Kill "fonmyr.mdb"

'   ' This statement creates a compact version of the
'   ' Northwind database that uses a Korean language
'   ' collating order.
'   DBEngine.CompactDatabase "fonmy.mdb", _
'      "fonmyr.mdb", dbLangCyrillic
'
'   Set dbsNorthwind = OpenDatabase("fonmyr.mdb")
'
'   ' Show the properties of the compacted database.
'   With dbsNorthwind
'      Debug.Print .Name & ", version " & .Version
'      Debug.Print "  CollatingOrder = " & .CollatingOrder
'      .Close
'   End With

End Sub

Private Sub mnuAbout_Click()
     frmSplash.Show
End Sub

Private Sub mnuExit_Click()
    End
End Sub

Private Sub mnuHelp_Click()
    FormHelp.Show
End Sub

Private Sub TabStrip1_Click()
Dim Ind As String
Ind = TabStrip1.SelectedItem
'If mztOr > 0 Then
'    ztOr = (ztOr + 1) Mod mztOr
 'Picture2.Picture = LoadPicture(MyFl(ztOr))
' Picture2.Picture = LoadPicture("D:\VT\VB\FonVT\Абсолют.wmf")
   Select Case Ind
   Case "Население"                             'население
            Picture2.Visible = True
            Picture1.Visible = False
            Picture3.Visible = False
        Case "Предприятия"                               'предприятия
            Picture3.Visible = True
            Picture2.Visible = False
            Picture1.Visible = False
        Case "Личный"                              'личные
            Picture1.Visible = True
            Picture2.Visible = False
            Picture3.Visible = False
   End Select
' If TabStrip1.Index = 2 Then frmDataEnv.Picture = "D:\VT\VB\FonVT\Цветок.wmf"
'End If

   If TabStrip1.SelectedItem.Index = mintCurFrame _
      Then Exit Sub ' No need to change frame.
   ' Otherwise, hide old frames, show new.

   Label2(0).Visible = False
   Label2(1).Visible = False
   Label2(2).Visible = False
   Label2(TabStrip1.SelectedItem.Index - 1).Visible = True
   Frame4(0).Visible = False
   Frame4(1).Visible = False
   Frame4(2).Visible = False
   Frame4(TabStrip1.SelectedItem.Index - 1).Visible = True
   Frame5(0).Visible = False
   Frame5(1).Visible = False
   Frame5(2).Visible = False
   Frame5(TabStrip1.SelectedItem.Index - 1).Visible = True
If Frame4(0).Visible Then
  Label7.Caption = "из " & Val(Data1.Recordset.RecordCount)
ElseIf Frame4(1).Visible Then
  Label7.Caption = "из " & Val(Data2.Recordset.RecordCount)
Else
  Label7.Caption = "из " & Val(Data3.Recordset.RecordCount)
End If
   ' Set mintCurFrame to new value.
   mintCurFrame = TabStrip1.SelectedItem.Index
    Tent_Change
    Form_Resize                             '  ******************************
    
End Sub

Private Sub Tedom_Change()
    If IsNumeric(Tedom.Text) Or Len(Tedom.Text) = 0 Then
        Te_Change
    Else
        MsgBox "Ввод номера дома, ЦИФРЫ" & vbCr & "Нажмите <Enter> или <OK>", vbCritical
        'If Len(Tent.Text) > 0 Then Tent.Text = Left(Tent.Text, Len(Tent.Text) - 1)
    End If
End Sub

Private Sub Tedom_GotFocus()
    gotfo = 4
    Te_Change
End Sub

Private Sub Tefio_Change()
    Te_Change
End Sub

Private Sub Tefio_GotFocus()
   gotfo = 2
   Te_Change
End Sub

Private Sub Tekv_Change()
    If IsNumeric(Tekv.Text) Or Len(Tekv.Text) = 0 Then
        Te_Change
    Else
        MsgBox "Ввод номера квартиры, ЦИФРЫ" & vbCr & "Нажмите <Enter> или <OK>", vbCritical
        'If Len(Tent.Text) > 0 Then Tent.Text = Left(Tent.Text, Len(Tent.Text) - 1)
    End If
End Sub

Private Sub Tekv_GotFocus()
    gotfo = 5
    Te_Change
End Sub

Private Sub Tent_Change()
'    If IsNumeric(Tent.Text) Or Len(Tent.Text) = 0 Then
        Te_Change
'    Else
'        MsgBox "Ввод номера телефона, ЦИФРЫ" & vbCr & "Нажмите <Enter> или <OK>", vbCritical
        'If Len(Tent.Text) > 0 Then Tent.Text = Left(Tent.Text, Len(Tent.Text) - 1)
'    End If
End Sub

Private Sub Tent_GotFocus()
    gotfo = 1
    Te_Change
End Sub

Private Sub Testr_Change()
   Te_Change
End Sub

Private Sub Testr_GotFocus()
    gotfo = 3
    Te_Change
End Sub

Private Sub Timer1_Timer()
Dim ca As String
Dim lca As Integer
Dim lt As Integer

ca = frmDataEnv.Caption
lca = Len(ca)

ca = Right(ca, lca - 1) & Left(ca, 1)
frmDataEnv.Caption = ca

lt = Len(Trim(Tent & Testr & Tedom & Tekv & Tefio))
If lt = 0 Then
    Command1.Enabled = False
Else
    Command1.Enabled = True
    End If
End Sub

Private Function ORDERBY() As String

Dim sqo As String

If gotfo = 1 Then
    sqo = " ORDER BY N_tel"
    Label1.Font.Bold = True
    Label2(0).Font.Bold = False
    Label2(1).Font.Bold = False
    Label2(2).Font.Bold = False
    Label3.Font.Bold = False
    Label4.Font.Bold = False
    Label5.Font.Bold = False
ElseIf gotfo = 3 Then
    sqo = " ORDER BY STREET, DOM, DOM1, KVART, KVART1"
    Label1.Font.Bold = False
    Label2(0).Font.Bold = False
    Label2(1).Font.Bold = False
    Label2(2).Font.Bold = False
    Label3.Font.Bold = True
    Label4.Font.Bold = True
    Label5.Font.Bold = True
ElseIf gotfo = 4 Then
    sqo = " ORDER BY DOM, DOM1, KVART, KVART1"
    Label1.Font.Bold = False
    Label2(0).Font.Bold = False
    Label2(1).Font.Bold = False
    Label2(2).Font.Bold = False
    Label3.Font.Bold = False
    Label4.Font.Bold = True
    Label5.Font.Bold = True
ElseIf gotfo = 5 Then
    sqo = " ORDER BY KVART, KVART1"
    Label1.Font.Bold = False
    Label2(0).Font.Bold = False
    Label2(1).Font.Bold = False
    Label2(2).Font.Bold = False
    Label3.Font.Bold = False
    Label4.Font.Bold = False
    Label5.Font.Bold = True
Else
    If mintCurFrame = 2 Then
        sqo = " ORDER BY PREDPR, PRIM"
    Else
        sqo = " ORDER BY FAMILY"
    End If
    Label1.Font.Bold = False
    Label2(0).Font.Bold = True
    Label2(1).Font.Bold = True
    Label2(2).Font.Bold = True
    Label3.Font.Bold = False
    Label4.Font.Bold = False
    Label5.Font.Bold = False
End If

ORDERBY = sqo
End Function
Private Sub Te_Change()
Dim sq As String
Dim sqo As String

Dim ord As Boolean

Dim lt As Integer
Dim st As String
On Error GoTo ErrorHandler
ord = False


If TabStrip1.SelectedItem.Index = 1 Then
'NASELEN
    sq = "Select * From NASELEN"
ElseIf TabStrip1.SelectedItem.Index = 2 Then
'PREDPR
    sq = "Select * From PREDPR"
Else
'NOTE
    sq = "Select * From fonmy.MY"
End If


    lt = Len(Trim(Tent.Text))
    If lt > 0 Then
        st = Left(Trim(Tent.Text), lt)
'        sq = sq & " WHERE left(N_tel," & lt & ") = '" & st & "'"
        sq = sq & " WHERE N_tel like '" & st & "*'"
        ord = True
    End If

lt = Len(Trim(Tefio.Text))
If lt > 0 Then
    st = Left(Trim(Tefio.Text), lt)
    If TabStrip1.SelectedItem.Index = 2 Then
    'PREDPR
        If ord Then
'            sq = sq & " AND left(PREDPR," & lt & ") = '" & st & "'"
            sq = sq & " AND PREDPR like '" & st & "*'"
        Else
'            sq = sq & " WHERE left(PREDPR," & lt & ") = '" & st & "'"
            sq = sq & " WHERE PREDPR like '" & st & "*'"
            ord = True
        End If
    Else
    'NASELEN, NOTE
        If ord Then
'            sq = sq & " AND left(FAMILY," & lt & ") = '" & st & "'"
            sq = sq & " AND FAMILY like '" & st & "*'"
        Else
'            sq = sq & " WHERE left(FAMILY," & lt & ") = '" & st & "'"
            sq = sq & " WHERE FAMILY like '" & st & "*'"
            ord = True
        End If
    End If
    
End If

lt = Len(Trim(Testr.Text))
If lt > 0 Then
    st = Left(Trim(Testr.Text), lt)
    If ord Then
        sq = sq & " AND STREET like '" & st & "*'"
    Else
        sq = sq & " WHERE STREET like'" & st & "*'"
        ord = True
    End If
End If

lt = Len(Trim(Tedom.Text))
If lt > 0 Then
    st = Left(Trim(Tedom.Text), lt)
    If ord Then
        sq = sq & " AND left(trim(DOM)," & lt & ") = '" & st & "'"
    Else
        sq = sq & " WHERE left(trim(DOM)," & lt & ") = '" & st & "'"
        ord = True
    End If
End If

lt = Len(Trim(Tekv.Text))
If lt > 0 Then
    st = Left(Trim(Tekv.Text), lt)
    If ord Then
        sq = sq & " AND Left(Trim(KVART)," & lt & ") = '" & st & "'"
    Else
        sq = sq & " WHERE Left(Trim(KVART)," & lt & ") = '" & st & "'"
        ord = True
    End If
End If

sqo = ORDERBY()
        
sq = sq & sqo

If TabStrip1.SelectedItem.Index = 1 Then
'NASELEN
    Data1.RecordSource = sq
    Data1.Refresh
    DBGrid1.ReBind
ElseIf TabStrip1.SelectedItem.Index = 2 Then
'PREDPR
    Data2.RecordSource = sq
    Data2.Refresh
    DBGrid2.ReBind
Else
'NOTE
    Data3.RecordSource = sq
    Data3.Refresh
    DBGrid3.ReBind
End If
Exit Sub      ' Exit to avoid handler.

ErrorHandler:   ' Error-handling routine.
   Select Case Err.Number   ' Evaluate error number.
      Case 3075   ' "File already open" error.
            MsgBox "Вы хотели сказать Э?" & vbCr & "Проверьте раскладку клавиатуры" & vbCr & "Нажмите <Enter> или <OK>", vbCritical
            Select Case gotfo
                Case 2
                    If InStr(Tefio.Text, "'") > 0 Then Tefio.Text = Left(Tefio.Text, InStr(Tefio.Text, "'") - 1) & "Э"
                Case 3
                    If InStr(Testr.Text, "'") > 0 Then Testr.Text = Left(Testr.Text, InStr(Testr.Text, "'") - 1) & "Э"
            End Select
      Case Else
         ' Handle other situations here...
   End Select
   Resume Next   ' Resume execution at next line
            ' that caused the error.

End Sub





