Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    jmitchelldueck is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    51
    Update: to force user to enter firstName prior to endName



    Code:
    Private Sub firstName_LostFocus()
    If IsNull(firstName) Then
        lastName.SetFocus
        firstName.SetFocus
        MsgBox "You must enter the physician's first name before leaving this field."
        
        End If
        
    End Sub
    The bit I posted before stopped working for some reason.

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Errors message, wrong results, nothing happens?

    Could set the fields as required in table and let Access nag users. They will eventually learn not to skip.

    Could use Validation Rule property instead of VBA.

    So once record is initiated or enters the firstname box, user cannot abort?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    jmitchelldueck is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    51
    The first code I had worked for the correct sequence of events, however I had it on GotFocus for the lastName field, so I was able to click away to another field lower down on the form. I changed it to LostFocus for the firstName field, which forces the user to enter a value before moving to another field. Upon further consideration, I will have a bit more tweaking to do. Will post final code when complete.

  4. #19
    jmitchelldueck is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    51
    Final update for anyone following this riveting storyline:

    Having the most recent code on LostFocus event for the firstName field did not make it possible for the user to exit the form without entering data into the firstName field, giving useless values in the table the form writes to.

    I replaced it with GotFocus events on every other entry field in my form that was programmed like so:
    Code:
    If IsNull(Me.firstName) Or IsNull(Me.lastName) Then
        MsgBox "Enter the physician's first and last names.", , "Physician Name"
        If IsNull(Me.firstName) Then
            firstName.SetFocus
        Else
            lastName.SetFocus
        End If
        
    End If
    I am now able to use all the buttons on the form and ensure blank or incomplete records aren't being written to the table, while still ensuring the user enters both first and last names. Thanks all for the help.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 29
    Last Post: 04-25-2014, 03:49 PM
  2. Replies: 11
    Last Post: 05-23-2012, 08:42 AM
  3. Replies: 3
    Last Post: 02-22-2012, 11:31 AM
  4. Replies: 0
    Last Post: 02-25-2011, 09:40 AM
  5. Replies: 9
    Last Post: 01-06-2011, 01:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums