Results 1 to 11 of 11

Thread: populate combobox from SQL db

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    populate combobox from SQL db

    Hello, I have been working at this for days and am no better off. I could really use some help.
    I need to populate a combobox with data from a column in an SQL table. I have put together the code below but am having an error at this line:

    invBegNum.additem rs.Fields.Item("RMDNUMWK").Value

    Error message:

    "Object doesn't support this property or method"

    I'm really a newb but am trying hard to get this. Here is the code. Please help.
    VB Code:
    1. Sub getInvData()
    2. Dim conn As ADODB.Connection
    3. Dim connString As String
    4.  
    5. conString = "Provider=sqloledb;Data Source=localhost;Initial Catalog=BBTN;User Id=scott;Password=bigdaddy"
    6.  
    7. Set conn = New ADODB.Connection
    8. conn.ConnectionString = conString
    9. conn.Open connString
    10.  
    11. Dim rs As ADODB.RecordSet
    12. Dim sSQL As String
    13.  
    14. Set rs = New ADODB.RecordSet
    15. sSQL = "select RMDNUMWK from SV00564 order by RMDNUMWK"
    16. rs.Open sSQL, conn
    17.  
    18. Do Until rs.EOF
    19. invBegNum.additem rs.Fields.Item("RMDNUMWK").Value
    20. rs.MoveNext
    21. Loop
    22. rs.Close
    23. conn.Close
    24. Set conn = Nothing
    25. Set rs = Nothing
    26.        
    27. End Sub









    Added vbcode tags - Hack
    Last edited by Hack; Jan 11th, 2006 at 08:34 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: populate combobox from SQL db

    The only thing that might possibly be wrong is that invBegNum is not the name of the Combobox control. I say this because additem is not in proper case, meaning intellisense could not find that property in that control.

    Is invBegNum an ImageCombo?

  3. #3
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: populate combobox from SQL db

    gogetsome:

    Just giving your code a quick glance it looks like you have an error here:

    conn.ConnectionString = conString
    conn.Open connString
    In the first line you have conString and in the second line you have connString.

    Make them both the same and see what happens.
    I think it should work.
    Hope this helps.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: populate combobox from SQL db

    Thank you AIS4U for the fat finger catch.

    brucevde the object is a combobox. I then tried to use a listbox and both receive the same error. Now, to show my newb. I'm trying to do this in VBA on a form in Great Plains. I thought that straight VB works but am unsure why the combobox does not accept .additem. Is there something else that could be causing this?

  5. #5
    Lively Member
    Join Date
    May 2005
    Location
    INDIA
    Posts
    65

    Re: populate combobox from SQL db

    hi,
    try this though your code seems to be all right

    <vbcode>comboname.additem("" &rs.fields("field_name"))<\vbcode>
    "What we are is not decided by our qualities,
    What we are is decided by our decisions"
    -Albus Dumbledore
    harry potter and the chamber of secrets

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: populate combobox from SQL db

    Thank you mohit_ranka for joining in this problem. I tried your suggestion of invbegnum.additem ("" &rs.Fields("rmdumwk")) but still receive the same message. This is crazy. When I hover over the errored out line I see the expected data so I know the recordset is being populated.

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: populate combobox from SQL db

    Post the Form where the problem occurs.

  8. #8
    Lively Member
    Join Date
    May 2005
    Location
    INDIA
    Posts
    65

    Re: populate combobox from SQL db

    can you post the error message?
    "What we are is not decided by our qualities,
    What we are is decided by our decisions"
    -Albus Dumbledore
    harry potter and the chamber of secrets

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: populate combobox from SQL db

    mohit_ranka the error reads:

    run-time error '438':
    Object doesn't support this porperty or method

    brucevde how do I get the code to post the form? I know how to do this in VS2005 but not in microsoft visual basic 6.3 VBA.

    Maybe this can help route out the problem:

    When I write this line of code, intellisence does not list .additem as a method or propery for invbegnum. This method property does belong to the combobox.

  10. #10
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: populate combobox from SQL db

    This might be an issue with VBA not having the same functionality of a normal vb language (.net or Vb6). I'm not sure, but it sounds like that might be the case.

    Edit: From what i've read around the forum it looks like the comboboxes in VBA don't have the additem property.

    Edit: I would try using the rowsource property.
    Last edited by space_monkey; Jan 11th, 2006 at 12:20 PM.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: populate combobox from SQL db

    Quote Originally Posted by gogetsome
    I'm trying to do this in VBA on a form in Great Plains.
    VBA question moved to Office Development (although I have no clue what Great Plains is.)

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