Results 1 to 6 of 6
  1. #1
    Dega is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Calgary, AB
    Posts
    73

    Sub form appearing based on main form condition

    Hi,



    I have a main form with a field (combo) that has a value of 1 (reservation) or 2 (guest). 1 will always represent who reserved tour/room and 2 will represent being a guest of 1. (multiple occupancy in one room).

    There are three sub forms in tab format and one is the booking form (strictly tour reservation details), the other is the form for room (reservation) and another is a form for the (guest) reservation.

    What I would like to do is make the sub forms reservation OR guest available for entry/viewing depending on the main form (combo) having a value of 1 or 2.

    The main form is saved at this point before going to the sub forms.

    I do not know VB and am wondering if I can do this without it?

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The basic code would look like:
    Code:
    If Me.ComboName = 1 Then
      Me.SubformControlName.Visible = True
    Else
      Me.SubformControlName.Visible = False
    End If
    You can add the other subform with the reverse visibility.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Dega is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Calgary, AB
    Posts
    73
    I am kinda green here so would that code be related to the subform itself (condition that opens the form?) and nothing would be in the main form properties.

    I don't know where to put your example (event procedure?) that will trigger the condition.

    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The two most likely places are the after update event of the combo and the current event of the main form. You may want it in both. The after update event of the combo will fire when you change its value. The current event will fire when you change records.

    Depending on how complicated the code gets, if you want it in both places I'd either create a function that did it and call the function from both events, or put the code in one event and call that event from the other. You want to avoid having the same code in two places, as then you have to keep both updated if you change something.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Dega is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Calgary, AB
    Posts
    73
    "The two most likely places are the after update event of the combo and the current event of the main form. You may want it in both. The after update event of the combo will fire when you change its value. The current event will fire when you change records."

    Thanks Paul,

    It works well even when toggling between records as I did it in both.

    I will digest the rest of your explanation as in creating a function to call both events later tonight.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help; post back if you get stuck on the rest.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 06-17-2010, 04:15 PM
  2. Replies: 1
    Last Post: 06-14-2010, 02:31 AM
  3. Replies: 6
    Last Post: 01-13-2010, 02:41 PM
  4. Replies: 0
    Last Post: 06-23-2009, 03:01 PM
  5. Replies: 6
    Last Post: 06-03-2009, 02:01 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