A couple of things:
1) This is an access question and you should post it there. (Access VBA also belongs in that forum)
2) You should ALWAYS name your buttons, before creating code for them. A good name could be cmd_Save (cmd short for command button) or btn_Save (what I personally use)
3) You should use the code tags arond your code:[code]Code goes here[/code] to increase the readability of it, thats what I did below.
4) You post 2 pieces of code with the same procedure name. That is bound to give errors in your application.
5) When doing string concatanation, you must enclose your string literals in double quotes "my string", whereas references to string VARIABLES should not have quotes around them.
Now, to the question at hand. How to inform the user that he is missing some information. Lets presume we have named the button btn_Save, then it could look something like this:
- Private Sub btn_Save_Click()
-
'Check that required info is provided and if so, save record
-
On Error GoTo Err_btn_Save_Click
-
-
'Check info
-
Dim strError as string
-
strError=""
-
If IsNull(Social_Security_Number.Value) Then strError = strError & vbNewLine & "Social Security Number"
-
If IsNull(FirstName.Value) Then strError = strError & vbNewLine & "FirstName"
-
If IsNull(LastName.Value) Then strError = strError & vbNewLine & LastName
-
-
'If errors were found, inform user and exit.
-
If strError & ""="" then
-
Msgbox "Please fill in these fields before submitting:" & strError,vbOkOnly,"Missing Info"
-
GoTo Exit_btn_Save_Click
-
End If
-
-
'Save the record
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_btn_Save_Click:
-
Exit Sub
-
-
Err_btn_Save_Click:
-
MsgBox Err.Description
-
Resume Exit_Command165_Click
-
-
End Sub