Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setfocus problem (Win2K SP3/Access97)

    Hi all,

    I'm having a problem with a data entry form that checks each field entry as the user tabs from field to field. If an entry is incorrect, I want the focus to return to the control with the incorrect entry and clear it. My code is as follows:

    Private Sub part_AfterUpdate()
    Dim test As Variant

    If IsNull(Me.part) Then
    MsgBox "Please enter a valid part number", vbOKOnly, "Woops!"
    Else
    test = DLookup("[partno]", "TblParts", "[partno] = " & Me.part)
    If IsNull(test) Then
    MsgBox "This part number is not in the parts list.", vbOKOnly, "Woopsadaisy!"
    Me.part.SetFocus
    Me.part = ""
    End If
    End If
    End Sub

    (Sorry, no indentation. Doesn't seem to carry through with copy/paste)


    At the moment if an incorrect entry is entered, the message box pops up and the focus just moves on to the next control in the tab order. I have tried changing the control referencing to "Forms![Formname]![part].setfocus" but the same thing happens. What am I missing?

    Thanks in advance,

    Ryan

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

    Re: setfocus problem (Win2K SP3/Access97)

    Use the before update event rather than the after update event.

    If an entry is incorrect set Cancel = true (i.e. put that in as a line of code) and the focus will automatically return to the control.
    Regards
    John



  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setfocus problem (Win2K SP3/Access97)

    Following on, is you control a text box or a combo box? - it may be worth using a list of values in a combo to prevent incorrect values being entered.

    ps. use the tag to get the indentation you require

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

    Re: setfocus problem (Win2K SP3/Access97)

    You fell into a trap I'm very familiar with (guess how <img src=/S/smile.gif border=0 alt=smile width=15 height=15>): trying to display a tag in a post, but ending up with the result of the tag. You meant the <!t>[tab]<!/t> tag to create indentation:

    <!t>[tab]<!/t>Some text

    results in

    Some text

    (I used the <!t>[t]<!/t> and <!t>[/t]<!/t> tags to display the square brackets surrounding a tag without letting the parser convert it.)

  5. #5
    New Lounger
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setfocus problem (Win2K SP3/Access97)

    Thanks everyone. Two questions answered for the price of one <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

    Darsha, I though about this but the parts list would be a bit too long to be practical in a combo box.

Posting Permissions

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