Results 1 to 8 of 8

Thread: [RESOLVED] Display Access table components in a combobox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Resolved [RESOLVED] Display Access table components in a combobox

    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

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Display Access table components in a combobox

    VB Code:
    1. Set rs = New ADODB.Recordset
    2.     Set conn = New ADODB.Connection
    3.     conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\yourdb.mdb;Uid=;Pwd=;"
    4.     conn.CursorLocation = adUseClient
    5.     conn.Open
    6.     rs.Open "SELECT * FROM `tbl_tablename`", conn
    7.     Do While Not rs.EOF
    8.         cmbComboBox.AddItem Trim(rs!fieldname & "")
    9.         rs.MoveNext
    10.     Loop
    11.        
    12.     rs.Close
    13.     Set rs = Nothing
    14.     conn.Close
    15.     Set conn = Nothing
    My usual boring signature: Something

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Display Access table components in a combobox

    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.

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Display Access table components in a combobox

    did you change the control names and the database name to match your program?
    My usual boring signature: Something

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Display Access table components in a combobox

    yes dclamp, it looks like this now:

    VB Code:
    1. Set rs = New ADODB.Recordset
    2.     Set conn = New ADODB.Connection
    3.     conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "C:\Documents and Settings\Leo & Glory\Mis documentos\ppe.mdb;Uid=;Pwd=;"
    4.     conn.CursorLocation = adUseClient
    5.     conn.Open
    6.     rs.Open "SELECT * FROM PPE", conn
    7.     Do While Not rs.EOF
    8.         cmbCombo6.AddItem Trim(rs!fieldname & "")
    9.         rs.MoveNext
    10.     Loop
    11.        
    12.     rs.Close
    13.     Set rs = Nothing
    14.     conn.Close
    15.     Set conn = Nothing

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Display Access table components in a combobox

    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 & "

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Display Access table components in a combobox

    Thaks Guys,

    Solved

  8. #8
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [RESOLVED] Display Access table components in a combobox

    dont forget to mark this thread as resolved, and give rep
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width