Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2015

    Unanswered: MsgBox after Lost Focus

    So, I am noobing on! =)

    After my textbox "CaseNumber" is losing focus, and if ISNull, then i want a msgbox to pop up and: "you have to type casenumber before you move on" and then set focus back at the casenumber textbox, so I avoid people typing in other stuff before they type in the casenumber...

    I've tried this so far, but just got error runtime: 5

    Private Sub txt_casenumber_LostFocus()
    Dim lngsvar As Long
    If IsNull(Me.txt_casenumber) Then
        lngsvar = MsgBox("Fill in casenumber first", vbCritical, vbOKOnly, "Please fill in?")
        If lngsvar = OK Then
        End If
    End If

    Thanks again =)

  2. #2
    Join Date
    Apr 2004
    Derbyshire, UK
    Provided Answers: 1

    I think
    vbCritical, vbOKOnly
    should be
    vbCritical + vbOKOnly


  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Mike is correct about the syntax for the that needs fixing, but the only event associated with a Control, such as a Textbox, that can keep/return Focus to that Control, is its BeforeUpdate event...and this event will only fire if the data has changed, either from it being Null to being populated or if existing data was modified. You can get around this, using the LostFocus event, by setting Focus to another Control and then back to the original Control.

    I understand your intent, here, but you have to understand that doing this type of validation, using an event of the Control being validated, is not practical, as all the user has to avoid it is to not enter the Control. If you force Focus on the Control, when a user starts to enter a New Record, you can avoid this, but then if the user decides to not enter a New Record, they're stuck!

    As a general rule, using a Control's events to do validation is only done when validating the data that has been entered...validating that a Control has actually been populated is properly done in the Form_BeforeUpdate event.

    Linq ;0)>
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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