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

Edited 3 Years Ago by pritaeas: Added markdown.

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
Comments
nice..
This question has already been answered. Start a new discussion instead.