Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Lewes, East Sussex, Sussex, United Kingdom
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SetFocus not working (A97 SR2)

    I have a main form with two combo boxes (cboFilter and cboField) on it which are used to enter data to populate a subform contained on the main form. I'm trapping blank entries on the combo box with the following code :

    Private Sub cboFilter_AfterUpdate()
    If IsNull(Me!cboFilter) Then
    Call msubDisplayMessage(gstrcAppName, "", 13, "Filter field", vbNullString)
    Me!cboFilter.SetFocus
    Exit Sub
    End If
    End Sub

    However the focus does not return to the control as expected - it just goes to wherever the cursor was last clicked. Has anyone encountered this problem ? More to the point, does anyone have any answers to get round it ?

    Thanks in advance for the help

    Nick

  2. #2
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus not working (A97 SR2)

    Nick

    You might want use BeforeUpdate for your test.

    If thats not possible issue somthing like the following might work:

    Me!cboField.SetFocus
    Me!cboFilter.SetFocus

    HTH, John

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Lewes, East Sussex, Sussex, United Kingdom
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus not working (A97 SR2)

    John

    Yes, the double SetFocus did the trick. Why this should be so I do not know, but it works & many thanks.

    Nick

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: SetFocus not working (A97 SR2)

    I think you're taking the long way around. If you use BeforeUpdate rather than AfterUpdate and set the Cancel argument to True, Access will refuse to allow the focus to ever leave cboFilter in the first place. Sample:
    <pre>Private Sub cboFilter_BeforeUpdate(Cancel As Integer)
    If IsNull(Me!cboFilter) Then
    Cancel = True
    Call msubDisplayMessage(gstrcAppName, "", 13, "Filter field", vbNullString)
    End If
    End Sub</pre>


Posting Permissions

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