Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Location
    All over, Now in Missouri
    Posts
    73

    Unanswered: Access VBA lost for the moment

    I have an Access form with 10 list boxes on it, when the user clicks the item they want, I have it open an input form for them to enter a class number. Works great, but I want to shorten my code, here is what I got:

    Note: every time they click the menu item, I want it to display my form

    Option Compare Database
    Dim stDocName As String
    Dim stLinkCriteria As String

    ' this will show the form for input
    Public Sub CallSel_Classnum()

    Forms!frmMenu_Popup_Sel_ClassNum!cbocla = Null
    Forms!frmMenu_Popup_Sel_ClassNum!cbocla.SetFocus
    Forms!frmMenu_Popup_Sel_ClassNum.visible = True

    End Sub


    ' this is A list menu
    Private Sub cboAList_Click()

    On Error GoTo Err_cmdAList_Click
    Forms!frmMenu_Main!txtcbolist = [cboAList]
    strcbolist = [cboAList]

    Call CallSel_Classnum

    Exit_cmdAList_Click:
    Exit Sub

    Err_cmdAList_Click:
    MsgBox Err.Description
    Resume Exit_cmdAList_Click
    End Sub


    ' this is B list menu
    Private Sub cboBList_Click()

    On Error GoTo Err_cmdBList_Click
    Forms!frmMenu_Main!txtcbolist = [cboBList]
    strcbolist = [cboAList]

    Call CallSel_Classnum

    Exit_cmdBList_Click:
    Exit Sub

    Err_cmdBList_Click:
    MsgBox Err.Description
    Resume Exit_cmdBList_Click
    End Sub



    ' this is C list menu
    Private Sub cboCList_Click()

    On Error GoTo Err_cmdCList_Click
    Forms!frmMenu_Main!txtcbolist = [cboCList]
    strcbolist = [cboCList]

    Call CallSel_Classnum

    Exit_cmdCList_Click:
    Exit Sub

    Err_cmdCList_Click:
    MsgBox Err.Description
    Resume Exit_cmdCList_Click
    End Sub
    We tend to look at Linear paths which can lead us to a path of resistance!

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Wrap it all up in a sub and call that sub from your click event handlers:
    Code:
    Private Sub HandleCboClick(ByRef targetComboBox As ComboBox)
    
    On Error GoTo Err_cmdCList_Click
    Forms!frmMenu_Main!txtcbolist = targetComboBox 
    strcbolist = targetComboBox 
    
    Call CallSel_Classnum
    
    Exit_cmdCList_Click:
    Exit Sub
    
    Err_cmdCList_Click:
    MsgBox Err.Description
    Resume Exit_cmdCList_Click
    End Sub
    
    
    ' this is A list menu
    Private Sub cboAList_Click()
       HandleCboClick(cboAList)
    End Sub
    
    
    ' this is B list menu
    Private Sub cboBList_Click()
       HandleCboClick(cboBList)
    Exit Sub
    
    ' this is C list menu
    Private Sub cboCList_Click()
       HandleCboClick(cboCList)
    End Sub
    *Note that's all untested psuedo-code for illustrative purposes only.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Apr 2008
    Location
    All over, Now in Missouri
    Posts
    73
    I am good to go, thanks

    peter
    We tend to look at Linear paths which can lead us to a path of resistance!

Posting Permissions

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