Hello, I have a form with a drop-down list that I would like to have populated with data from a database. Can someone show me an example of how this is accomplished or point me to a tutorial?
Without pointing you directly you will probably need to look at 2 tutorials / faq's.
1. For retreiving the data from a adatabase, perhaps using ADO
&
2. Populating a combo box (actually really simple, just using the .AddItem method of the combo box object.
Thanks niceguymattx for pointing me in the right direction. I'm learning.
I think that I'm on the right track but it's not working. I'm getting an error that the varible at: ReDim Preserve aryCodeList(0, lngIndex) is not declared. I admit that Im new to this and following an example. I'm also unsure if I have the code in the right location. I want the drop-down list to populate on page load. Could you please advise?
Here is the code:
Private Sub Window_AfterActivate()
Dim conn As New ADODB.Connection
conn.Open "Provider=sqloledb;Data Source=localhost;Initial Catalog=BBTN;User Id=xxx;Password=xxx"
Dim RecordSet As New ADODB.RecordSet
RecordSet.Source = "select RMDNUMWK from SV00564"
Set RecordSet.ActiveConnection = conn
RecordSet.Open
If RecordSet.EOF = True Then GoTo BYE
Dim lngIndex As Long
lngIndex = -1
Do Until RecordSet.EOF
lngIndex = lngIndex + 1
ReDim Preserve aryCodeList(0, lngIndex)
aryCodeList(0, lngIndex) = grsPrimary.Fields("RMDNUMWK")
RecordSet.MoveNext
Loop
RecordSet.Close
invBegNum.Value = RecordSet
End Sub
Option Explicit forces you to declare your variables. You need to declare aryCodeList as a variable.
Look up Ubound and LBound in Help. You need to loop through the array, taking each item in the array and using Combobox.AddItem array item to add to the combo.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.