Add message "Record has been saved"

hardhitter06

Registered User.
Local time
Today, 14:07
Joined
Dec 21, 2006
Messages
600
Hi all,

I have this code that requires me to enter in each of the fields in a form or else when the record is saved it will return an error message telling what fields still need to be filled in. It works fine, but when I hit the save button to verify if i'm missing any fields (even though I'm not), I want it to tell me the record has been saved so the user knows. If there are no fields missing right now, and you click the save button, nothing happens (although the record is saved).

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnError As Boolean
Dim strError As String

strError = "You are missing data for one or more of these fields:"

If IsNull(Me.[Account #]) Or Me.[Account #] = "" Then
blnError = True
strError = strError & "Account #,"
End If

If IsNull(Me.Vendor) Or Me.Vendor = "" Then
blnError = True
strError = strError & " and/or Vendor,"
End If

If IsNull(Me.[Total Amount]) Or Me.[Total Amount] = "" Then
blnError = True
strError = strError & " and/or Total Amount,"
End If

If IsNull(Me.Category) Or Me.Category = "" Then
blnError = True
strError = strError & " and/or Category,"
End If

If IsNull(Me.[Contract #]) Or Me.[Contract #] = "" Then
blnError = True
strError = strError & " Contact,"
End If

If IsNull(Me.[Term Begins]) Or Me.[Term Begins] = "" Then
blnError = True
strError = strError & " and/or Term Begins,"
End If

If IsNull(Me.[Term Ends]) Or Me.[Term Ends] = "" Then
blnError = True
strError = strError & " and/or Term Ends,"
End If

If IsNull(Me.[Record Date]) Or Me.[Record Date] = "" Then
blnError = True
strError = strError & " and/or Record Date,"
End If

If blnError Then
strError = Left(strError, Len(strError) - 1)
If MsgBox(strError & vbCrLf & "Are you sure you want to cancel." & vbCrLf & "If you do, the info will not be added.", vbQuestion + vbYesNo, "Close Confirmation") = vbNo Then
Cancel = True
End If
 
OR macro code to the save button, not sure where to add the code.

Would like to display, MsgBox "The record has been saved.", vbOKOnly. Just not sure where to add it in??


Private Sub Command27_Click()
On Error GoTo Err_Command27_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub
 
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "The record has been saved.", vbOKOnly <HEREE!!!

FYI you dont need all that code. you can do

DoCmd.RunCommand acCmdSaveRecord
 
Wow, that was toooo easy. Thank you so much! Since you helped me with that, I kind of have a similar question...if you have some free time, do you think you could look at

http://www.access-programmers.co.uk/forums/showthread.php?p=618987#post618987

I'm trying to allow the user to select "No" (dont cancel) so I can continue to finish adding in the fields I've missed, but when I hit No, it cancels the form anyways
 

Users who are viewing this thread

Back
Top Bottom