Opening a form from a combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • damonrulz
    New Member
    • Sep 2008
    • 13

    Opening a form from a combo box

    I have a combo box with a list in. I want to be able to click
    on one of the values in this combo box, and a form will open. The difficult thing is that i want a different form to open for each value in the combo box. Preferably a macro. Any suggestions on how I might be able to achieve this?

    Thanks
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    In all code, where your values in the combobox are

    one, two, three, four

    and the forms are

    Form1, Form2, Form3, Form4

    Code:
    Private Sub YourComboName_AfterUpdate()
     Select Case YourComboName
    
       Case "one"
        DoCmd.OpenForm "Form1"
       Case "two"
        DoCmd.OpenForm "Form2"
       Case "three"
        DoCmd.OpenForm "Form3"
       Case "four"
        DoCmd.OpenForm "Form4"
    
     End Select
    End Sub
    Or if you already have macros made to open each form
    Code:
    Private Sub YourComboName_AfterUpdate()
     Select Case YourComboName
       
    Case "one"
        DoCmd.RunMacro "OpenForm1Macro"
       Case "two"
        DoCmd.RunMacro "OpenForm2Macro"
       Case "three"
        DoCmd.RunMacro "OpenForm3Macro"
       Case "four"
        DoCmd.RunMacro "OpenForm4Macro"
    
     End Select
    End Sub
    You will, of course, have to replace the combobox name, all combobox values and form names with your actual names.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • damonrulz
      New Member
      • Sep 2008
      • 13

      #3
      Originally posted by missinglinq
      In all code, where your values in the combobox are

      one, two, three, four

      and the forms are

      Form1, Form2, Form3, Form4

      Code:
      Private Sub YourComboName_AfterUpdate()
       Select Case YourComboName
      
         Case "one"
          DoCmd.OpenForm "Form1"
         Case "two"
          DoCmd.OpenForm "Form2"
         Case "three"
          DoCmd.OpenForm "Form3"
         Case "four"
          DoCmd.OpenForm "Form4"
      
       End Select
      End Sub
      Or if you already have macros made to open each form
      Code:
      Private Sub YourComboName_AfterUpdate()
       Select Case YourComboName
         
      Case "one"
          DoCmd.RunMacro "OpenForm1Macro"
         Case "two"
          DoCmd.RunMacro "OpenForm2Macro"
         Case "three"
          DoCmd.RunMacro "OpenForm3Macro"
         Case "four"
          DoCmd.RunMacro "OpenForm4Macro"
      
       End Select
      End Sub
      You will, of course, have to replace the combobox name, all combobox values and form names with your actual names.

      Welcome to Bytes!

      Linq ;0)>
      Thanks mate, that worked great!

      It's for my A-Level project, so this will impress them a little more.

      Thanks for the great advice and welcoming

      Comment

      Working...