Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 27 of 27

Thread: Solved: Populate a comboxbox and Listbox in a excel userform with an sql table data

  1. #21

    Smile Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi Tinbendr,

    Thanks a lot for replying on my post. I have just now checked the file attached by you. I didn't find any sub routine in module1 as mentioned by you in your recent post. Apart from this We I try to run the form it shows me the following error.

    [VBA]Run-time error '-2147217900 (80040e14)'
    Incorrect syntax near ')'
    [/VBA]

    When I click on debug after facing the above error. It highlights below line

    [VBA]Set rst = .Execute(stSQL)[/VBA]

    Though when I debug it highlights above line but I think there is something wrong with the below sql statement.

    [VBA]stSQL = "SELECT DISTINCT CONVERT(VARCHAR(50), " & ComboBox1 & ") FROM Region_Mapping"[/VBA]

    I am re-attaching the macro file and the sql table Region_Mapping which I have copied into excel.

    Thanks a lot for your help in advance.

  2. #22

    Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi Tinbendr,

    Did you get the chance to look at the above post. I am awaiting for your reply.


    Thanks a lot for your help in advance.

  3. #23

    Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi Tinbendr,

    Did you get the chance to look at the above post. I am awaiting for your reply.


    Thanks a lot for your help in advance.

  4. #24

    Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi Tinbendr,

    Did you get the chance to look at the above post. I am awaiting for your reply.


    Thanks a lot for your help in advance.

  5. #25
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Hover over stSQL to make sure the string is being formed correctly.

    If you do not select something from the listbox, it will error out.

    David


  6. #26

    Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi Tinbendr,

    Please help me with code line. I am bit confused. According the following code line should be used for populating countries in listbox1

    [VBA]sSQL = "SELECT DISTINCT Country FROM Region_Mapping WHERE Country = '" & ComboBox1.Value & "' "[/VBA]

    Can you please help me in replicating above code in such a way that the listbox get populated with countries on the basis of region selection.
    for e.g. If I select America in combo box then it should show Brazil, Argentina, USA and Mexico countries which are mapped against america in sql table.

    Thanks for your help in advance.

  7. #27

    Populate a comboxbox and Listbox in a excel userform with an sql table data

    Hi All,

    Finally I got it. The issue was with the below sql statement .i.e instead of region I had mentioned country in the same.

    SELECT DISTINCT Country FROM Region_Mapping WHERE Region = '" & ComboBox1.Value & "' "

    Any how. Thanks a lot for your help.

Posting Permissions

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