Consulting

Results 1 to 7 of 7

Thread: populating combobox from access table

  1. #1

    Question populating combobox from access table

    I am relatively new to programming and have an issue I can't seem to overcome. I'm creating a user form and two comboboxes are required. I need them to populate by reading from two separate access tables. Here is what I have so far:



    Private Sub UserForm_Initialize()


    Dim dbConnection As Object
    Dim recordSet As Object
    Dim strSQL As String
    Dim strConnectionConfig As String


    Set dbConnection = CreateObject("ADODB.Connection")


    strConnectionConfig = "Provider=Microsoft.ACE.OLEDB.12.0;" _
    & "Data Source = ASSIGNMENT 4.accdb;"


    dbConnection.Open (strConnectionConfig)


    strSQL = "SELECT DISTINCT DOCTORID FROM DOCTOR"


    Set recordSet = dbConnection.Execute(strSQL)


    SETAPPTUF.DRIDCB.AddItem ("ALL")


    Do While (Not recordSet.EOF)
    SETAPPTUF.DRIDCB.AddItem (recordSet("DOCTORID"))

    recordSet.MoveNext
    Loop


    strSQL = "SELECT DISTINCT PATIENTID FROM PATIENT"


    Set recordSet = dbConnection.Execute(strSQL)


    SETAPPTUF.PTIDCB.AddItem ("ALL")


    Do While (Not recordSet.EOF)
    SETAPPTUF.PTIDCB.AddItem (recordSet("PATIENTID"))
    recordSet.MoveNext
    Loop




    End Sub


    Any help is appreciated.

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Please use code tags.

    This is all you need:
    Sub Access_query_combobox_snb()
        With CreateObject("ADODB.Connection")
            .Open "SELECT * FROM Q_test", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Access\fiets.mdb"
            ComboBox1.Column = .GetRows
        End With
    End Sub

  3. #3
    Using this suggestion still did not put the required lists into the two boxes, but I did get help on another. Thanks for responding.

    Quote Originally Posted by snb View Post
    Please use code tags.

    This is all you need:
    Sub Access_query_combobox_snb()
        With CreateObject("ADODB.Connection")
            .Open "SELECT * FROM Q_test", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Access\fiets.mdb"
            ComboBox1.Column = .GetRows
        End With
    End Sub

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    If you are crossposting: that's not being appreciated !

    And: do not Quote !

  5. #5
    Again...relatively new. Not sure what you mean by "crossposting"? From context, it seems you are saying that once I ask for help it is somehow impolite to keep looking for my own answer through other resources? That seems kind of ridiculous, but if that is a generally accepted attitude then I may have to reconsider asking for help. I was under the impression that these forums were to help each other. I'm sorry if I was mistaken. Thanks for letting me know that self-help is not "appreciated".

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    http://www.vbaexpress.com/forum/faq...._new_faq_item3
    crossposting from FAQ...


    http://www.excelguru.ca/content.php?184


    this is what snb meant when you said "i did get help..."
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  7. #7
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    .......
    Last edited by mancubus; 04-10-2017 at 05:46 AM. Reason: duplicate post
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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