Results 1 to 5 of 5
  1. #1
    rlsublime is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    58

    User Required Field

    I entered the following code to the before update event to require a user to enter a value in the field and then set the focus back to the field so they can try to enter the value again, but it is generating an error. Any idea what I have done wrong here? Thanks





    Code:
    Private Sub Loan_Number_BeforeUpdate(Cancel As Integer)
    If IsNull(Me!Loan_Number) Then
        MsgBox "Loan Number is required", vbOKOnly, "Required Field Missing"
        Cancel = True
        Me.Loan_Number.SetFocus
    End If
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Cancel = True will hold the focus in the control. No need for any SetFocus code.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    BTW, You only get a BeforeUpdqate event when the user has actually *changed* the value in the control.

  4. #4
    rlsublime is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    58
    thanks. is there a way to get it to display the message when there is no value and not only where there is an update made? I tried adding the required field code to a save button command. It displayed a message if the field was blank but it also saved. What I am trying to do is alter the following code to do is NOT save if a required field is still blank. Any thoughts on this? Thanks

    Code:
    Private Sub Command199_Click()
    
    If IsNull(Me!Loan_Number.Value) Then
              MsgBox "Please enter Loan Number"
              Cancel = True
           End If
    On Error GoTo Err_Command199_Click
    
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Exit_Command199_Click:
        Exit Sub
    Err_Command199_Click:
        MsgBox Err.Description
        Resume Exit_Command199_Click
        
    End Sub

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can only set Cancel *IF* it is passed to you in the procedure as it is in the BeforeUpdate event. What you want to do can be done in the BeforeUpdate event of the FORM. If you don't want to save then just do Me.UnDo and it reverts the controls to what they were originally.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cancel when there is a required field
    By dougie in forum Forms
    Replies: 3
    Last Post: 03-07-2012, 09:38 AM
  2. Replies: 3
    Last Post: 01-15-2012, 02:46 PM
  3. Save as Draft but mandatory field is not required
    By zuerin in forum Programming
    Replies: 5
    Last Post: 06-30-2011, 01:42 AM
  4. Required Field Help
    By brandonb in forum Access
    Replies: 4
    Last Post: 11-13-2009, 11:18 AM
  5. Set required user input
    By ZeusOsiris in forum Database Design
    Replies: 2
    Last Post: 12-04-2006, 07:13 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