Hello everyone. I have a userform in an excel spreadsheet that has two combo boxes on it (for now, more stuff willl be added). In the first combo box, the user may select from two options: Customer or Terminal. (I have that part up-and-running). For the second combobox what needs to get done is trickier.
Depending on what the user selects I need the following to occur:
1. If the user selects "Customer", then the second combo box will contain a list of Customers. That list is in an Access databse table called Customers.
2. If the user selects "Terminal", then the second combobox will contain a list of terminals. That list is in an Access databse table called Terminals.
I am using this Private sub to create the database connection:
The userform is launched via:Public Sub CreateConnection() Dim DataSource As String Dim DataFolder As String Dim DS As String On Error GoTo ConnectionError Set conn = New ADODB.Connection DataSource = Sheets(VALIDATIONS).Range("W2").Value If DataSource = "" Or Dir(DataSource) = "" Then DataSource = ThisWorkbook.Path & "\PIPELINETRACKER.MDB" Sheets(VALIDATIONS).Range("W2").Value = DataSource End If DataFolder = VBA.Left(DataSource, InStrRev(DataSource, "\")) conn.Provider = "Microsoft.Jet.OLEDB.4.0;" conn.ConnectionString = "Data Source=" & DataSource & ";Jet OLEDB:Database Password=ProtectMDB;" conn.Mode = adModeShareDenyNone conn.Open Exit Sub ConnectionError: If DataFolder <> "" Then Err.Clear DataSource = DataFolder & "PIPELINETRACKER.MDB" On Error Resume Next conn.Provider = "Microsoft.Jet.OLEDB.4.0;" conn.ConnectionString = "Data Source=" & DataSource & ";Jet OLEDB:Database Password=ProtectMDB;" conn.Mode = adModeShareDenyNone conn.Open If Err.Number = 0 Then Exit Sub End If If Err.Number <> 0 Or DataFolder = "" Then Err.Clear DS = Application.GetOpenFilename("Access Database (*.mdb), *.mdb") If DS <> "False" Then DataSource = DS DataFolder = VBA.Left(DataSource, InStrRev(DataSource, "\")) Sheets(VALIDATIONS).Range("W2").Value = DataSource Set conn = New ADODB.Connection conn.Provider = "Microsoft.Jet.OLEDB.4.0;" conn.ConnectionString = "Data Source=" & DataSource & ";Jet OLEDB:Database Password=ProtectMDB;" conn.Mode = adModeShareDenyNone conn.Open Else Application.Quit End If End If End Sub
Any help is greatly appreciated. I am developing using Access and Excel 97.Option Explicit Private Sub Button4_Click() Application.ScreenUpdating = False TrackerManagementForm.Show End Sub
Last edited by AnthonyWB; 01-03-2011 at 12:02 AM. Reason: spelling error
OK, I admit, this is a cheesy way to do it, but I still use. Create two combo boxes (give each a name), one for Terminals and one for customers. make them the same size. Place one on top of the other one. In your click event of your first combo box, decide which one to show.
So basically if = terminal, hide customer, show terminal combo box.
Just set one to one as hidden and one as visible or both invisible initially.
Since you have each combobox setup with it's own query, your golden.
makes life easier.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks