I have built a farily extemsive multipage userform for user input. The userform will populate an excel spreadsheet to begin with, and eventually (hopefully) populate an access database. I have used an example from another forum to populate my main combobox with a list in an access database stored on my C:\ drive. For maintenance alone, I believe this is definitely the better way to go however, this spreadsheet has been used by my company for the past 10 years, and they are still wanting to hold on to it for now.
What I have in place is code to establish a connection with the database, find the field it is told to look for, and list it in the combobox on the userform. What I need it to do is populate residual text boxes on the userform based on the selection made in the combobox that is populated by the access database. My code looks like this:
Private Sub UserForm_Initialize()
On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Databases\StaffDatabase.mdb"
rst.Open "SELECT DISTINCT [Department] FROM tblStaff ORDER BY [Department];", _
cnn, adOpenStatic
rst.MoveFirst
With Me.ComboBox1
.Clear
Do
.AddItem rst![Department]
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub
again, this is a sample that I found using google. What I need to determine is how to ask the program to connect with more than one field (I think), and to automatically return the value of the subsequent fields in the text boxes on the userform. Additionally, I'm not sure if a 'change_event' might be the necessary trigger to populate to text boxes? I hope I am clear enough as I am unsure if 'I' understand my needs properly?
If anyone can provide either insight, examples, or links, it would be greatly appreciated. I have scoured several different forums for the past few weeks and have found examples of nearly everthing that I don't need, and nothing specific to what I do need.
Also, I would like to know if this is simply some rendition of a VLookup or a direct database query?
Again, any insight would be greatly appreciated.
Thanks and Regards,
What I have in place is code to establish a connection with the database, find the field it is told to look for, and list it in the combobox on the userform. What I need it to do is populate residual text boxes on the userform based on the selection made in the combobox that is populated by the access database. My code looks like this:
Private Sub UserForm_Initialize()
On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Databases\StaffDatabase.mdb"
rst.Open "SELECT DISTINCT [Department] FROM tblStaff ORDER BY [Department];", _
cnn, adOpenStatic
rst.MoveFirst
With Me.ComboBox1
.Clear
Do
.AddItem rst![Department]
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub
again, this is a sample that I found using google. What I need to determine is how to ask the program to connect with more than one field (I think), and to automatically return the value of the subsequent fields in the text boxes on the userform. Additionally, I'm not sure if a 'change_event' might be the necessary trigger to populate to text boxes? I hope I am clear enough as I am unsure if 'I' understand my needs properly?
If anyone can provide either insight, examples, or links, it would be greatly appreciated. I have scoured several different forums for the past few weeks and have found examples of nearly everthing that I don't need, and nothing specific to what I do need.
Also, I would like to know if this is simply some rendition of a VLookup or a direct database query?
Again, any insight would be greatly appreciated.
Thanks and Regards,