Results 1 to 5 of 5
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Help with VBA to have combobox open/close forms


    Hi, I'm looking to see if its possible to have code open and close various forms based on a combobox.

    Basically, I've got form1, form2, and form3. I want to have a combobox allows the user to select one of the three forms in order to change forms quicker. So basically if the user is in form1, and selects form2, then the code would close form1 and open form2.

    Any recommendations on how to code it? I found one tutorial online but its for opening subforms within a main form via a comboxbox. I'm looking to do it for 3 distinct main forms.

    Thanks!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Set the Row Source property of the combo to Value List
    Set the Row Source property of the combo to form1; form2; form3
    In the After Update event of the combo use Select Case to determine which form has been selected.
    One line of code to open the selected form and another to close the current form.
    Post back if you need help with the code for the After Update event.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    The code would look something like this
    Code:
    'save record as you are about to close the form
    Me.Dirty=False
    Docmd.OpenForm Me.cboFormSelector
    Docmd.Close acForm, Me.Name
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by templeowls View Post
    Hi, I'm looking to see if its possible to have code open and close various forms based on a combobox.

    Basically, I've got form1, form2, and form3. I want to have a combobox allows the user to select one of the three forms in order to change forms quicker. So basically if the user is in form1, and selects form2, then the code would close form1 and open form2.

    Any recommendations on how to code it? I found one tutorial online but its for opening subforms within a main form via a comboxbox. I'm looking to do it for 3 distinct main forms.

    Thanks!
    Here's an example of how it might be done:
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Thank you so much!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2021, 11:04 PM
  2. Replies: 6
    Last Post: 03-27-2017, 03:16 AM
  3. Close an open PDF file
    By StaceyE in forum Programming
    Replies: 2
    Last Post: 12-01-2015, 06:28 AM
  4. Replies: 8
    Last Post: 04-12-2014, 01:29 PM
  5. Replies: 1
    Last Post: 05-03-2012, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums