I have a combobox that i want to display items from a single row table from MSAccess.
How can i do this?
Thanks in advance
Printable View
I have a combobox that i want to display items from a single row table from MSAccess.
How can i do this?
Thanks in advance
VB Code:
Set rs = New ADODB.Recordset Set conn = New ADODB.Connection conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\yourdb.mdb;Uid=;Pwd=;" conn.CursorLocation = adUseClient conn.Open rs.Open "SELECT * FROM `tbl_tablename`", conn Do While Not rs.EOF cmbComboBox.AddItem Trim(rs!fieldname & "") rs.MoveNext Loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing
Thanks for the reply DClamp,
I´m getting an error:
Runtime Error '-2147467259(80004005)
[Microsoft][Microsoft access ODBC Controller] It´s not a valid file name.
did you change the control names and the database name to match your program?
yes dclamp, it looks like this now:
VB Code:
Set rs = New ADODB.Recordset Set conn = New ADODB.Connection conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "C:\Documents and Settings\Leo & Glory\Mis documentos\ppe.mdb;Uid=;Pwd=;" conn.CursorLocation = adUseClient conn.Open rs.Open "SELECT * FROM PPE", conn Do While Not rs.EOF cmbCombo6.AddItem Trim(rs!fieldname & "") rs.MoveNext Loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing
dclamp used App.Path to automatically detect the program path (assuming that the mdb file is in the same folder as the program), so you need to remove " & App.Path & "
Thaks Guys,
Solved
dont forget to mark this thread as resolved, and give rep ;)