Results 1 to 2 of 2

Combobox via Select Case

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Combobox via Select Case

    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:

    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
    The userform is launched via:

    Option Explicit
    Private Sub Button4_Click()
    
    Application.ScreenUpdating = False
    
    TrackerManagementForm.Show
    
    End Sub
    Any help is greatly appreciated. I am developing using Access and Excel 97.
    Last edited by AnthonyWB; 01-03-2011 at 01:02 AM. Reason: spelling error

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1