Ok heres the code behind the button to add a record it checks all the fields are populated correctly and if one field is unique (UserName) it lets the user know this record has been added. If not it tells them were they went wrong. No compile errors brilliant I thought
However on clicking this button i get a error saying Access can't find field |1 in your expression. I've done a search and am really straining my head at this one
Thanks in anticipation
Chris
However on clicking this button i get a error saying Access can't find field |1 in your expression. I've done a search and am really straining my head at this one
Code:
Private Sub SaveRecord_Click()
Dim errmsg As String
On Error GoTo Err_SaveRecord_Click
'Check the validity of the data entered into the fields.
'No blank values for user name.
If IsNull([User Name]) Then
MsgBox "You must enter a value for User Name.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Surname].SetFocus
[User Name].SetFocus
'User name must start with a "u".
ElseIf Left$([User Name], 1) <> "u" Then
MsgBox "The user name must start with a 'u' or 'v'.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Surname].SetFocus
[User Name].SetFocus
'No blank values for First Name.
ElseIf IsNull([First Name]) Then
MsgBox "You must enter a value for First Name.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[First Name].SetFocus
'No blank values for Surname.
ElseIf IsNull(Surname) Then
MsgBox "You must enter a value for Surname.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
Surname.SetFocus
'No blank values for Address
ElseIf IsNull([Address]) Then
MsgBox "You must enter a value for the address.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Address].SetFocus
'No blank values for Town
ElseIf IsNull(Town) Then
MsgBox "You must enter a value for the Town.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
Town.SetFocus
'No blank values for County
ElseIf IsNull(County) Then
MsgBox "You must enter a value for county.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
County.SetFocus
'No blank values for Post Code
ElseIf IsNull([Post Code]) Then
MsgBox "You must enter a value for the post code.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Post Code].SetFocus
'No blank values for Date of Birth
ElseIf IsNull([Date of Birth]) Then
MsgBox "You must enter a value for Date of Birth.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Date of Birth].SetFocus
'No blank values for Date Enrolled
ElseIf IsNull([Date Enrolled]) Then
MsgBox "You must enter a value for the enrollment date.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Date Enrolled].SetFocus
'No blank values for ethnicity
ElseIf [Ethnicity] = 0 Then
MsgBox "You must indicate Ethnicity.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
[Ethnicity].SetFocus
'No non gender people!
ElseIf [Male/Female] = 0 Then
MsgBox "You must indicate gender.", vbExclamation, "NCC Visits"
DoCmd.CancelEvent
Else
'Save the record and let the user know.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "New user entered successfully.", vbInformation, "NCC Visits"
DoCmd.Close
End If
Exit_SaveRecord_Click:
Exit Sub
Err_SaveRecord_Click:
'User name is already in use.
If Err.Number = 3022 Then
MsgBox "That user name is in use, please select another.", vbExclamation, "NCC Visits"
[User Name].SetFocus
Else
'Error that I haven't thought of
errmsg = "An unusual error has occurred. Please make a note of this description." + Chr(13) + Err.Description + Chr(13) + Str(Err.Number)
MsgBox errmsg, vbExclamation, "NCC Visits"
End If
Resume Exit_SaveRecord_Click
End Sub
Chris