I want to connect my macro with a table of access to fill my ComboBox but it doesn't work me
File is archivio.mdb
Table is commesse
Fiels is numero
Code is
Private Sub ComboBox1_Change()
Dim db02 As ADODB.Connection
Dim rs02 As ADODB.Recordset
Dim stringa As String
stringa = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
stringa = stringa & "D:\\archivio.mdb"
Set db02 = New ADODB.Connection
db02.ConnectionString = stringa
db02.Open
Set rs02 = New ADODB.Recordset
rs02.Open ("commesse", db02,adOpenDynamic,adLockOptimistic )
rs02.movefirst
Do While Not rs02.EOF
ComboBox1.AddItem rs02.Fields("numero")
rs02.MoveNext
Loop
rs02.Close
End Sub
Thanks
aLberto
SolidworksApi macros
check connection string
check the database name, table name is coincident.
check other website for more referrence.
by the way, commessa<>commesse
Do you get any sort of error?
Try getting rid of .fields, as in Recordset("Fieldname") instead of Recordset.Fields("Fieldname")
Try an ODBC connection to .mdb access files
yes, it is only on the machine. this is the odbc shortage
but it is an easy start,right?
I think that the error is in this line
rs02.Open ("commesse", db02,adOpenDynamic,adLockOptimistic )
Option Explicit
Private Sub CommandButton1_Click()
Dim db02 As ADODB.Connection
Dim rs02 As ADODB.Recordset
Dim stringa As String
stringa = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
stringa = stringa & "D:\archivio.mdb"
Set db02 = New ADODB.Connection
db02.ConnectionString = stringa
db02.Open
Set rs02 = New ADODB.Recordset
rs02.Open "SELECT numero FROM commesse", db02, adOpenDynamic, adLockOptimistic
rs02.movefirst
Do While Not rs02.EOF
ComboBox1.AddItem rs02.Fields("numero").Value
rs02.MoveNext
Loop
rs02.Close
End Sub