I want to populate combo box with particular field value of a table in ms access.

datafile = "D:\database.accdb"
With cn
.Provider = "microsoft.ACE.OLEDB.12.0"
.ConnectionString = datafile
End With
cn.Open
Set rs = cn.Execute("select * from mytable")

Do Until rs.EOF
combo1.AddItem rs!name
rs.MoveNext
Loop

cn.Close

I am getting runtime error 3705 provider of object connection failed

Try this :

Private Sub Form_Load()
    Dim Conn As New ADODB.Connection
    Dim rs As ADODB.Recordset

    Set Conn = New ADODB.Connection
    Conn.Provider = "Microsoft.ACE.OLEDB.12.0"
    Conn.CursorLocation = adUseClient
    Conn.Open "D:\database.accdb"

    Set rs = New ADODB.Recordset
    rs.Open "select * from mytable", Conn, adOpenDynamic, adLockBatchOptimistic

    While Not rs.EOF
        Combo1.AddItem rs!name
        rs.MoveNext
    Wend
    rs.Close

End Sub
commented: nice.. +3

thanks .it works fine now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.