Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    SetFocus problem (Access XP)

    I have a main form and 2 sub forms. My problem is when I have not entered a mainform record (the first field on the main form is an autonumber field name TrainerID) and the TrainerID is null and I move my mouse to either of the subforms I want to stop the program in it's tracks and tell the user to enter a main form first. I have put code into the GotFocus of the subform testing the TrainerID of the main form to null and if so try to set the focus to TrainerID of the main form and an error occurs telling me I cannot set the focus to that control at this time.

    Help

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

    Re: SetFocus problem (Access XP)

    I have solved it.
    What I did was to put the following code in the OnEnter event of both subforms, only the message box is different.
    <pre>
    Private Sub SF_Tags_Enter()
    If IsNull(Forms![frm Application]!TrainerID) Then
    MsgBox "Please enter the Trainer information first before entering the tags !!"
    Forms![frm Application]!TrainerName.SetFocus
    End If
    End Sub
    </pre>


    As can be seen I wnet back to the first field (field TrainerName) after the Autonumber field (field TrainerID).

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

    Re: SetFocus problem (Access XP)

    Another approach would be to disable the subform(s) by default and only enable them if there is a parent form record. That completely prevents them from going to the subform before it is legal and serves as a visual warning of that condition without any need for a message box. Of course, you will get users who call to say their form is broken because they can't go to the subform, <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15> but those users won't read the messagebox either and will call to say they're getting an error message, so .... <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Charlotte

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

    Re: SetFocus problem (Access XP)

    Thanks Charlotte.

    I'll keep that in mind especially if they start to complain about a broken subform and a message box they choose to ignore.

  5. #5
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus problem (Access XP)

    Just have the message box show up 3 times <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15> They'll be sure to read it then!
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

Posting Permissions

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