Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If/Else statement (A2k)

    I have 4 tabbed pages (one main form with 3 subforms). The last control on my first page a checkbox. If the box is checked the 2nd page will activate. The code that is currently in the OnExit event is Me.sbfGuests.Visible=chkGuest. If the preceding statement equates to false, I want to set focus on the first control of the 3rd subform. Is this how I would write the code?
    If chkGuest =True Then
    Me.sbfGuests.Visible=True
    Else
    Me.Parent!sbfStudentClasses.SetFocus
    Me.Parent!sbfStudentClasses.Form!intClassId.SetFoc us

    ???

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    There is some confusion here. In the "True" part of If ... Then ... Else ..., you refer to Me.sbfGuests, implying that sbfGuests is a subform of the form that contains the check box. In the "False" part you refer to Me.Parent!sbfStudentClasses, implying that the check box itself is on a subform (Parent is the main form). So there would be a hierarchy as in the attached picture. Is that what you intended?
    Attached Images Attached Images
    • File Type: png x.png (2.9 KB, 0 views)

  3. #3
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    If I'm reading your post correctly, the true part is correct, but the false part is not. The check box is on the main form--If the check box is not checked, I want to set focus to intClassId (first control on 3rd subform). Shall I just leave out Parent!?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    Yes, remove the two occurrences of Me.Parent! (and don't forget to add End If after it if necessary - you probably have it already, but it's not apparent in your post)

  5. #5
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Here's what I've got, and it's not working:
    Private Sub chkGuest_Exit(Cancel As Integer)
    If chkGuest = True Then
    Me.sbfGuests.Visible = True
    Else
    sbfStudentClasses.SetFocus
    sbfStudentClasses.Form!intClassID.SetFocus
    End If
    End Sub
    Where did I go wrong this time?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    Please, try to be specific. You write "it's not working" - do you get an error message, or does it do something you didn't intend (if so, what), or does it do nothing at all (if chkGuest is checked, or clear, or both)?

  7. #7
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Whether the box is checked or not, it skips the sbfGuests and goes straight to the sbfStudentClasses. If I click on the sbfGuests tab, it will display, just not when I'm tabbing through.

    Exactly what I need it to do is this:

    Enter a brand new record and check the check box indicating the student has a guest
    The sbfGuests becomes visible immediately
    If the check box is not checked, focus is automatically set to first control on sbfStudentClasses

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    Try using the AfterUpdate event of the check box (as I recommended in <post#=260819>post 260819</post#>) instead of the On Exit event.

  9. #9
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Thanks for the reminder, Hans

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    But did it help?

  11. #11
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Unfortunately, no. I'm just trying to figure it out on my own--I don't want to keep bugging you with this. It keeps jumping straight to the sbfStudentClasses without regard to the check box checked or not. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    You can try to single step through the code:
    <UL><LI>Click in the grey margin of the form module to the left of Private chkGuest_AfterUpdate()
    <LI>A brown bullet should appear in the margin, and the line should be highlighted in brown.
    <LI>Switch back to Access, open the form, and click the check box.
    <LI>You should be taken back to Visual Basic, with the line now highlighted in yellow.
    <LI>You can inspect the value of variables and controls in the code by hovering the mouse pointer above them; the value of the check box should be either 0 (false) or -1 (true)
    <LI>By pressing F8 repeatedly you can step through the code one instruction at a time.
    <LI>This way, you can see what code is executed.[/list]Can you see if sbfGuests.Visible is ever executed? And is chkGuest ever -1?

  13. #13
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Upon following your instruction I get the following error message:
    Compile Error-Invalid use of property
    The word Visible is highlighted behind the error message

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If/Else statement (A2k)

    This is getting stranger and stranger. Could you do the following - it'll make it easier to investigate what's going on.
    <UL><LI>Make a copy of the database and work with that.
    <LI>Remove all database objects (tables, queries, forms, reports, modules) that are NOT relevant to the problem.
    <LI>In the remaining table(s), remove most records - leave only the minimum number necessary to demonstrate the problem.
    <LI>Remove or modify data of a confidential nature.
    <LI>Do a compact and repair (Tools/Database Utilities).
    <LI>Make a zip file containing the database; it should be below 100KB.
    <LI>Attach the zip file to a reply.[/list]Thanks

  15. #15
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If/Else statement (A2k)

    Here you go
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Posting Permissions

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