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

    SetFocus Not Working for Me? (A2k (9.0.3821) SR-1)

    SetFocus Not Working for Me?

    A2k (9.0.3821) SR-1

    I have the following code in after update event which works fine if the format rules are followed.

    If there is an error, the message works OK, however Me!strCONTACT.SetFocus is not taking me back to the field with error.

    The focus goes to next field.

    How can I return the focus back to strCONTACT if there is error, without using Before Update Cancel = True?

    Thanks, John


    Err_strCONTACT_AfterUpdate:

    If Err.Number = 3163 Then ' Field too small to accept the amount of data
    ' you attempted to add

    MsgBox Err.Description & " - " & "Error Number: " & Err.Number _
    & vbLf & vbLf & vbCr & _
    " Example of valid Contact Names format are: " _
    & vbLf & vbLf & vbCr & _
    " John Brown" _
    & vbLf & vbCr & _
    " John B. Brown" _
    & vbLf & vbCr & _
    " John Brown Jr." _
    & vbLf & vbCr & _
    " John B. Brown Jr." _
    & vbLf & vbCr & _
    " Mr. John B. Brown Jr." _
    & vbLf & vbCr & _
    " Mr. John B. Brown Jr., Consultant"
    Me!strCONTACT.SetFocus
    Exit Sub

    Else
    MsgBox Err.Description & " " & Err.Number
    End If

    Resume Exit_strCONTACT_AfterUpdate

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Not Working for Me? (A2k (9.0.3821) SR-1)

    I suppose strContact is an unboud field because if it is bound you can't enter to long strings.
    You have to do the control in the Before Update event.
    Then if there is an error you just set Cancel = True and don't use set focus.
    <pre>Private Sub NAAM_BeforeUpdate(Cancel As Integer)
    If Len(Me.strCONTACT) > XX then
    Msgbox ".........."
    Cancel = True
    exit Sub
    End Sub</pre>

    Replace XX with the number of characters allowed in the field where strContact will be set.
    I
    Francois

  3. #3
    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 for Me? (A2k (9.0.3821) SR-1)

    Hi Francois

    I switched it and its bullet proof now.

    I keep trying to swim against the tide with my procedural background. Thanks for slapping me around with event programming concepts.

    Point of interest. SetFocus does work in after update event for normal navigation. Is it the error that ignores the SetFocus?

    Thanks, John

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Not Working for Me? (A2k (9.0.3821) SR-1)

    I really don't know.
    Pure guessing : When you exit a field, you can set the focus to a control, but Access don't accept to return the control that you exit, because you just ask to exit ?
    When you use cancel = true in the before update, you intercept the command to exit the control and cancel it.
    Francois

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

    Re: SetFocus Not Working for Me? (A2k (9.0.3821) SR-1)

    SetFocus doesn't work for the control that currently has the focus in Access. If I remember correctly that syntax works in VB.
    Charlotte

Posting Permissions

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