• Can Not Set Focus problem (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Can Not Set Focus problem (Access 2000)

    Author
    Topic
    #404576

    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

    Viewing 0 reply threads
    Author
    Replies
    • #824050

      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? smile

      • #824058

        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

        • #824066

          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.

          • #824068

            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.

            • #824074

              Let’s see what dazednconfused has to say.

            • #824104

              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

              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

            • #824105

              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

              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

            • #824075

              Let’s see what dazednconfused has to say.

          • #824069

            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.

        • #824067

          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.

      • #824059

        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

    Viewing 0 reply threads
    Reply To: Can Not Set Focus problem (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: