borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: Load a combo box using DAO

Author  

David Costelloe

Language  

VB4, VB5, VB6

Operating Systems  

Windows 95, 98 and NT
Usage

Public Sub LoadCombo()
    Dim MyDatabase As DAO.Database
'Use this method if you are also using ADO
    Dim MyRecordset As DAO.Recordset
' Use it anyways save an error or Type Mismatch
    Dim MySql As String

    MySql = "SELECT DISTINCT [Item] FROM [Table] WHERE [Item]='" & strVar & "'"

    Set MyDatabase = DBengine.Workspaces(0).OpenDatabase("C:\MyData.mdb")
    Set MyRecordset = MyDatabase.OpenRecordset(MySql, DbOpenSnapShot)
    Do While Not MyRecordset.EOF
        If Not IsNull(MyRecordset("Item")) Then
            Combo1.Add MyRecordset("Item")
        End If
        MyRecordset.MoveNext
    Loop
   
'* Clean Up
    MyRecordset.Close
    MyDatabase.Close
    Set MyRecordset = Nothing
    Set MyDatabase = Nothing
   
'* Load the first record in combo
    If Combo1.ListCount > 0 Then
        Combo1.ListIndex = 0
    End If
End Sub

:: Navigation

Home

Database Management

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 06-04-2007 database visual basic 2005 by eira_ak
icon 25-10-2006 Re: press Tab in Tab control? by admin
icon 23-09-2006 Taking out Limitation of Image Combo by matt_1ca
icon 02-09-2006 Re: Related To Error Handling by yronium
icon 25-05-2006 VB compile error with Access 2003 Form across network by ba1959nh
Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder