|
-
Jan 10th, 2006, 05:54 PM
#1
Thread Starter
New Member
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:
Sub getInvData()
Dim conn As ADODB.Connection
Dim connString As String
conString = "Provider=sqloledb;Data Source=localhost;Initial Catalog=BBTN;User Id=scott;Password=bigdaddy"
Set conn = New ADODB.Connection
conn.ConnectionString = conString
conn.Open connString
Dim rs As ADODB.RecordSet
Dim sSQL As String
Set rs = New ADODB.RecordSet
sSQL = "select RMDNUMWK from SV00564 order by RMDNUMWK"
rs.Open sSQL, conn
Do Until rs.EOF
invBegNum.additem rs.Fields.Item("RMDNUMWK").Value
rs.MoveNext
Loop
rs.Close
conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
Added vbcode tags - Hack
Last edited by Hack; Jan 11th, 2006 at 08:34 AM.
-
Jan 10th, 2006, 06:19 PM
#2
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?
-
Jan 10th, 2006, 06:24 PM
#3
Frenzied Member
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.
-
Jan 11th, 2006, 09:02 AM
#4
Thread Starter
New Member
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?
-
Jan 11th, 2006, 09:54 AM
#5
Lively Member
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
-
Jan 11th, 2006, 10:36 AM
#6
Thread Starter
New Member
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.
-
Jan 11th, 2006, 11:06 AM
#7
Re: populate combobox from SQL db
Post the Form where the problem occurs.
-
Jan 11th, 2006, 11:11 AM
#8
Lively Member
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
-
Jan 11th, 2006, 11:36 AM
#9
Thread Starter
New Member
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.
-
Jan 11th, 2006, 11:58 AM
#10
Fanatic Member
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
-
Jan 11th, 2006, 01:42 PM
#11
Re: populate combobox from SQL db
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|