Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2013
    Posts
    6

    Unanswered: How to open a specific form from selection made

    Hi,

    This is my first time posting. I am pretty new to access. I am trying to make a simple inventory database for computers, printers, phones, etc. I have a combo box that links to a table with a list of devices like above. I need to figure out how to get a form to open when a certain option is chosen. For example, if I select Printers in the combo box, I need the printers form to open. If I select phones, my phone form would open. If anyone has some sample code that would help me, i would appreciate it. Please let me know where the code would go. Would it go in the query criteria or in the combo box properties.

    Thanks
    TheChad33

  2. #2
    Join Date
    Nov 2013
    Posts
    6

    Access 2010

    This is in Access 2010

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The code needs to be in the AfterUpdate event of the Combobox; something along these lines, replacing the names in the code for the Combobox and Forms with your actual names, and replacing the item values (i.e. PCs, Printers,etc) with the actual values for each item in the Combobox:

    Code:
    Private Sub cboDevices_AfterUpdate()
     
     Select Case Me.cboDevices
      
      Case "PCs"
       
       DoCmd.OpenForm "frmPCS"
      
      Case "Printers"
       
       DoCmd.OpenForm "frmPrinters"
      
      Case "Phones"
       
       DoCmd.OpenForm "frmPhones"
     
     End Select
    
    End Sub

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Nov 2013
    Posts
    6

    That gets me started but...

    Ok.. I'm sure my syntax is all wrong here. I tried this..

    Option Compare Database

    Private Sub Combo0_AfterUpdate()

    Select Case Me.Combo0
    Case "Desktop"
    DoCmd.OpenForm (DesktopF)
    Case "Printer"
    DoCmd.OpenForm (PrinterF)
    Case "Laptop"
    DoCmd.OpenForm (LaptopF)
    End Select


    End Sub


    Should I be referring to my Table instead of using Private Sub Combo0_AfterUpdate()

    With the above code. it still doesn't do anything when I select the option.

    Thanks again for any help.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    is combo the name of the combo box that has your options
    when you translated missinglinq's code to take not of your forms names did you use his syntax or create some syntax of your own

    what happens if you put a break point on the code

    persoanlly if I were you I'd also put a case else statement so you knwo if the code is exectuing but the case statement is not getting a value it recognises

    Code:
    Case "Laptop"
    DoCmd.OpenForm (LaptopF)
    case else
      msgbox "Oh shaggy my code crapped out. Combobox0 value is " & Combo0 & " and I don't know what to do with that"
    End Select
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Your use of

    DoCmd.OpenForm (LaptopF)

    is not correct syntax! It has to be

    DoCmd.OpenForm "LaptopF"

    as shown in my example. And again, as healdem asked, is your Combobox actually named Combo0?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Nov 2013
    Posts
    6

    Yep

    Yep its called Combo0. I was just playing around with syntax and thought I would try the other way. This is what I currently have and can't seem to get it to open the form. Do I need the Me in front of the Combo0 or should something else be there. It's not a big deal if I get this to work but it looks cleaner than putting a bunch of buttons on a form to open each form.



    Private Sub Combo0_AfterUpdate()

    Select Case Me.Combo0
    Case "Desktop"
    DoCmd.OpenForm "DesktopF"
    Case "Printer"
    DoCmd.OpenForm "PrintersF"
    Case "Laptop"
    DoCmd.OpenForm "LaptopF"
    End Select


    End Sub

    Private Sub Detail_Click()

    End Sub


    Thanks and Happy Thanksgiving
    Chad

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Have you proved the afterupdate event firing?
    Is it possible that the value in combo isnt one of the three specified items in the case statement.
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Nov 2013
    Posts
    6

    My bad

    Ok, i figured it out. My table that the combo box referred to has an equipment ID. So a Desktop equipment ID was 1 and a laptop was 2 and so on. I put the ID in instead of the name. It opens a window with a text search box and then will open the correct form.

    Thanks again for the help.

  10. #10
    Join Date
    Nov 2013
    Posts
    6

    Angry Access crashes

    I had it working. But when I close out the app and open the database again, I open the form with the combo box and select my choise. When that happens, I get a Microsoft Access message saying it has stopped working. "Windows can check online for a solution to the problem and try to recover your information and restart the program" I click on View problem details and it gives me the info listed below. I redid the combo box and ended up with the same issue. It works at first. I close the app. Open the app and try again and it crashes.

    Problem signature:
    Problem Event Name: APPCRASH
    Application Name: MSACCESS.EXE
    Application Version: 14.0.6024.1000
    Application Timestamp: 4d83e4fc
    Fault Module Name: VBE7.DLL
    Fault Module Version: 7.0.16.19
    Fault Module Timestamp: 4d430aec
    Exception Code: c0000005
    Exception Offset: 00023081
    OS Version: 6.1.7601.2.1.0.256.48
    Locale ID: 1033

    Additional information about the problem:
    LCID: 1033
    skulcid: 1033

    Read our privacy statement online:
    Windows 7 Privacy Statement - Microsoft Windows

    If the online privacy statement is not available, please read our privacy statement offline:
    C:\Windows\system32\en-US\erofflps.txt

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    This code isn't going to cause that problem, unless you have some form of corruption in the db.

    Id be tempted to open a new db and copy all the objects from the current db
    then compile it
    I'd rather be riding on the Tiger 800 or the Norton

Tags for this Thread

Posting Permissions

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