Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    go back to a control in the main form (Access 2000)

    Go back to a control in the main form

    After i have selected the controls in the main form,i open a control in the subform called [Protocols]. In the BeforeUpdate event of this control
    i have put the folowing code:

    If IsNull([Forms]![main]![Student]) Then
    DoCmd.Beep
    MsgBox " Please select a student first! ! "
    Exit Sub
    End If

    It means that if the control Student in the main form is not selected,then the above code must be trigggered.However
    nothing happens, if i have not selected a student ,i am allowed to enter into the control Protocols in the subform without any problem,without
    indication of errors, but the code seems not to work.Is it possible that i refer improper ly to the main form once i have entered the subform?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: go back to a control in the main form (Access 2000)

    Breakpoint the If Isnull line, and step from there (F8 steps a single command at a time).
    Put the mouse over Forms]![main]![Student]) and see what it contains.
    HTH
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: go back to a control in the main form (Access 2000)

    Is the main form actually named "Main"? I is often easier to use Me.Parent to refer to the parent of a subform, as in Me.Parent.Student; this way you don't really need to know the mainform name in your code.

    Are you saying that the msgbox is not being displayed at all? If so, as Pat pointed out, you might want to use debug to step thru your code to see why the actual value of [Student] is. Additionally, even if it is being displayed, your code still accepts the entry. You need to add a line of code "Cancel = True" to your code as follows.
    .....
    Msgbox .......
    Cancel = True
    Exit sub
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: go back to a control in the main form (Access 2000)

    You will only trigger the beforeupdate event of the Protocols control if you enter data or change the data in that control. Otherwise, the BeforeUpdate event doesn't get triggered. What you want to do is use the Enter event of the subform control itself. Make your test there and if the Student control is null, set the focus back to the main form's student control instead of proceeding to enter the subform.
    Charlotte

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: go back to a control in the main form (Access 2000)

    This seems to be the same question as in <post#=179242 >post 179242 </post#> Instead of trying to catch cases where a student was not entered, lock or disable to whole subofrm until they have entered a student.

    A danger with your code is that if you enter a [protocol] when there is no student, you will not be able to go back and put in the student, because whenever you try you will trigger the before update event, and be sent back to the [protocol] control.
    Regards
    John



Posting Permissions

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