Content Supported by Sourcelens Consulting

VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmDESQL 
   Caption         =   "Select Order by City"
   ClientHeight    =   3030
   ClientLeft      =   7890
   ClientTop       =   2310
   ClientWidth     =   7155
   LinkTopic       =   "Form1"
   ScaleHeight     =   3030
   ScaleWidth      =   7155
   Begin VB.CommandButton cmdBind 
      Caption         =   "Bind"
      Height          =   390
      Left            =   5745
      TabIndex        =   3
      Top             =   120
      Width           =   1365
   End
   Begin VB.TextBox txtCustomer 
      DataField       =   "CompanyName"
      DataMember      =   "Customers"
      DataSource      =   "deNwind"
      Height          =   315
      Left            =   1650
      TabIndex        =   2
      Top             =   435
      Width           =   2880
   End
   Begin MSDataGridLib.DataGrid grdData 
      Height          =   2115
      Left            =   120
      TabIndex        =   1
      Top             =   885
      Width           =   6945
      _ExtentX        =   12250
      _ExtentY        =   3731
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Orders By Vendor"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   1635
      Sorted          =   -1  'True
      TabIndex        =   0
      Text            =   "Combo1"
      Top             =   90
      Width           =   3765
   End
   Begin VB.Label lblVendorName 
      Caption         =   "Vendor Name"
      Height          =   270
      Left            =   60
      TabIndex        =   5
      Top             =   435
      Width           =   1215
   End
   Begin VB.Label lblcombo 
      Caption         =   "City"
      Height          =   255
      Left            =   30
      TabIndex        =   4
      Top             =   60
      Width           =   720
   End
End
Attribute VB_Name = "frmDESQL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private popFlag  As Boolean

Private Sub cmdBind_Click()
    ' Clear the ComboBox control. Set the popFlag so the
    ' ComboBox control's Click event doesn't fire while
    ' it's being populated by city names.
    Combo1.Clear
    popFlag = True
    ReShape
    
    Dim f As Field
    
    While Not deNwind.rsCustomers.EOF
        If CheckForDup(deNwind.rsCustomers) = False Then
           Combo1.AddItem deNwind.rsCustomers.Fields("City").Value
        End If
        deNwind.rsCustomers.MoveNext
    Wend
    
    Combo1.ListIndex = 0
    
    popFlag = False
    RequeryAndRebind
End Sub

Private Sub Combo1_Click()
    If popFlag = True Then Exit Sub
    RequeryAndRebind
End Sub

Private Function CheckForDup(ByRef rsX As Recordset) As Boolean
    Dim i As Integer
    For i = 0 To Combo1.ListCount - 1
        If Combo1.List(i) = rsX.Fields("City") Then
            CheckForDup = True ' We have a duplicate.
            Exit Function
        End If
    Next i
    CheckForDup = False
End Function
Private Sub RequeryAndRebind()
    
    With deNwind.rsCustomers
        If .State = adStateOpen Then .Close
        Dim x As Connection
        Set x = .ActiveConnection
        If x.State = adStateOpen Then x.Close
        .Source = "SELECT " & _
        "* FROM Customers WHERE City = '" & Combo1.Text & "'"
        x.Open
        .Open , x
    End With
    
    With txtCustomer
        Set .DataSource = deNwind
        .DataMember = "Customers"
        .DataField = "CompanyName"
    End With
    
    With grdData
        .DataMember = "customers"
        Set .DataSource = deNwind
    End With
End Sub

Private Sub Form_Resize()
    With grdData
        .Width = frmDESQL.Width - 500
        .Height = frmDESQL.Height - grdData.Top - 500
    End With
End Sub