Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can Not Set Focus problem (Access 2000)

    Dear All

    Hello again. I have a form sub form set up in Access, by using the sub form's enter event (on the main form event list) I'm trying to carry out a check for data validation and depending on the result set the focus back to a control on the main form. So far everything I've tried has resulted in error messages along the lines of "Can Not Set Focus to 'control name'".

    I've tried the lost focus event on the main form, didn't trigger at all so no good.

    I've tried using Docmd.GotoControl "controlname" and got a very similar error message.

    I've tried the control name prefixed Form!FormName!ControlName.Setfocus, no luck.

    The control I'm trying to set the focus to is both enabled and not locked, I've also tried a few other controls on the same form, thinking it might be a check box thing, but the same problem resulted.

    Anyone got any ideas? Please

    Ian
    Attached Files Attached Files

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

    Re: Can Not Set Focus problem (Access 2000)

    You will have to set focus to the main form before setting focus to a control on the main form. You can refer to the main form as Me.Parent, so:

    If ... Then
    Me.Parent.SetFocus
    Me.Parent!ControlName.SetFocus
    End If

    Is this a database for pease pudding? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

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

    Re: Can Not Set Focus problem (Access 2000)

    When the enter event of the subform control executes, the Main form is still 'Me" , so I think Hans code referring to me.parent will give an error (if used in that event)

    I have just done some testing using a similar set up and found this worked as required.

    Private Sub frmenrolmentssub_Enter()

    If Forms!frmstudents![studentsurname] = "Brown" Then

    forrms!frmstudents![studentsurname].SetFocus

    etc
    Regards
    John



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

    Re: Can Not Set Focus problem (Access 2000)

    There is no problem with "Me" here. Me is not the same as the active form, Me refers to the form whose module contains the code.

    But there is another problem: if the user is working in the main form, then clicks in the control on the subform that already was the active control of the subform, the On Enter event does not occur, so focus is not moved if necessary. The On Got Focus event does occur, but you have to be careful: if the condition to move focus out of the subform is met, it will become impossible to select *any* control in the subform until the cause has been remedied.

  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: Can Not Set Focus problem (Access 2000)

    Hans

    When I put me.parent.setfocus in the code I posted above, it threw an error.

    When I put in msgbox(me.name), the name displayed was frmstudents.

    The code in the onenter event of the subform is actually in the module of the main form, because the onenter event is attached to the subform control on the mainform.

    What do you think is being validated here.

    My understanding is that the user is working in the main form, and Ian wants to prevent entry to the subform until the main form has been vaildated.
    Regards
    John



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

    Re: Can Not Set Focus problem (Access 2000)

    Let's see what dazednconfused has to say.

  7. #7
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can Not Set Focus problem (Access 2000)

    OK, thanks for the feedback. I've tried most of it and I'm still getting the same result, I have had some different error messages though, so a little variety into my boring life [img]/forums/images/smilies/smile.gif[/img]

    I'm going to have a look at the possible use of the sub form as a 'pop-up' opened dialogue mode. I can get the same overall result that way.

    Thanks for the info, if I ever get to the bottom of the problem I'll let you know.

    Ian

Posting Permissions

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