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
Module

Public Const strJetProvider = "Provider=Microsoft.Jet.OLEDB.3.51;DataSource=C:\myaccess.mdb"

Usage

'* Place on a form a combo box and a command button

Public sub Command1_Click()

    Dim MyConn As New ADODB.Connection
    Dim MyRst As New ADODB.Recordset
    Dim strTemp As String


    With MyConn
        .ConnectionString = strJetProvider
        .Open
    End With
    With Me
        .Combo1.Clear
    End With
    MyRst.Open "SELECT * FROM SQL", MyConn, adLockReadOnly, adLockOptimistic, adCmdText

    If MyRst.RecordCount <= 0 Then
        MyRst.Close
        MyConn.Close
        Set MyRst = Nothing
        Set MyConn = Nothing
        strTemp = MsgBox("Sorry No Records are located?", vbOKOnly + vbCritical, "No Records Found")
        Exit Sub
    End If
    Do While Not MyRst.EOF
        If Not IsNull(MyRst("Field")) Then
            Combo1.AddItem MyRst("Field")
        End If
        MyRst.MoveNext
    Loop
    MyRst.Close
    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