Results 1 to 4 of 4
  1. #1
    tambadal is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    2

    beforeUpdate command

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
       Dim strMissingInfo As String
       Dim strMsg As String
    
    
        If IsNull(Me.[Debarred]) Then
           Cancel = True
           strMissingInfo = strMissingInfo & "Debarred"
            Else
    
    
        If IsNull(Me.[Restricted]) Then
           Cancel = True
           strMissingInfo = strMissingInfo & "Restricted"
        End If
    
    
        If IsNull(Me.[CommType]) Then
           Cancel = True
           strMissingInfo = strMissingInfo & "CommType"
        End If
    
    
        If IsNull(Me.[Approval_Status]) Then
           Cancel = True
           strMissingInfo = strMissingInfo & "Approval_Status"
           End If
    
    
        If Nz(strMissinginfo) = "" Then
           strMsg = "The following are required: " & strMissginInfo
           MsgBox strMsg
        End If
    
    
    End Sub
    I have this code in before update command. However, it seems like my code never got run through. it does not give me any error and still save data even required fields are not filled. Can anyone help me by pointing out what i'm doing wrong? Thank you

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'd use the test here:

    http://www.baldyweb.com/BeforeUpdate.htm

    which will test for both Null and a zero length string. Also this test is backwards:

    Code:
    If Nz(strMissinginfo) = "" Then
    should either be <> or

    Code:
    If Len(strMissinginfo) > 0 Then
    It's a string variable so can't possibly be Null.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tambadal is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    2
    Code:
    Dim strMissingInfo As String
    Dim strMsg As String
    
    
      On Error GoTo Command228_Click_Err
      On Error Resume Next
        
        
       If IsNull(Me.[Debarred]) Then
                MsgBox "You Must make a Selection in the Debarred Field"
    
    
        Else
        
        If IsNull(Me.[Restricted]) Then
                MsgBox "You Must make a Selection in the Resticted Field"
        Else
    
    
        If Me.[CommType].Value = "NA" Then
                MsgBox "You Must make a Selection in the Commodity Type Field"
        Else
        
        If Me.[Approval_Status].Value = "NA" Then
                MsgBox "You Must make a Selection in the Approval Status Field"
        Else
        
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.GoToRecord , "", acNewRec
        
        End If
        End If
        End If
        End If
    Thank you for your respond. I have come up with this code. However, my goal is to get it to check all the required fields and then will have message box in the end to list which required fields are not filled yet before saving. Do you know what changes can i make to my code to achieve that goal. Thank you for your help.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Your initial structure was fine, I was suggesting instead of

    If IsNull(Me.[Debarred]) Then

    you use

    If Len(Me.[Debarred] & vbNullString) = 0 Then

    plus change the test of the string at the end.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. BeforeUpdate: Why is 50 greater than 250?
    By Micron in forum Programming
    Replies: 6
    Last Post: 10-26-2016, 11:45 AM
  2. BeforeUpdate in a form
    By tcheck in forum Access
    Replies: 4
    Last Post: 07-28-2016, 03:09 PM
  3. Using the Form.BeforeUpdate property
    By Access_Novice in forum Programming
    Replies: 6
    Last Post: 01-01-2014, 08:45 PM
  4. Beforeupdate to early
    By R_Badger in forum Forms
    Replies: 3
    Last Post: 02-09-2012, 10:38 AM
  5. Validation BeforeUpdate Errors
    By huv123 in forum Programming
    Replies: 3
    Last Post: 02-07-2011, 10:25 AM

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