MysticElaine
Registered User.
- Local time
- Today, 04:48
- Joined
- May 26, 2014
- Messages
- 24
I am trying to add a recordset to my button to see if a client exists. A client exists in the table Clients if all three fields (First Name, Last Name and DOB) are identical to what the user is typing into the text boxes (named the same) to add a client.
My recordset comes up with the error: the rst.FindFirst that the Microsoft Access database engine does not recognize 'Me.First Name' as a valid field name or expression.
Thanks
My recordset comes up with the error: the rst.FindFirst that the Microsoft Access database engine does not recognize 'Me.First Name' as a valid field name or expression.
Code:
Private Sub AddNewClient_Click()
If IsNull([First Name]) Or IsNull([Last Name]) Or IsNull(DOB) Then
MsgBox "All fields are required", vbOKOnly, "Error"
Else
Dim dbs As Database
Dim rst As DAO.Recordset
Dim str As String
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Clients", dbOpenDynaset)
rst.FindFirst "[First Name] = Me.[First Name] AND [Last Name] = Me.[Last Name] AND [DOB] = Me.[DOB]"
If Not rst.NoMatch Then
MsgBox "Client exists"
GoTo Cleanup:
Else
If Me.First_Name <> "" And Me.Last_Name <> "" And Me.DOB <> "" Then
Dim ClName As Variant
Dim ClientID As Integer
ClientID = Me.Client_ID.Value
ClName = Me.Client_Name.Value
Forms![Case]![Client ID].Value = ClientID
Forms![Case]![Client].Value = ClName
Forms![Case]![Date Requested].Enabled = True
Forms![Case]![Staff Requesting].Enabled = True
Forms![Case]![Language Requested].Enabled = True
Forms![Case]![Service Requested].Enabled = True
Forms![Case]![Service Date].Enabled = True
Forms![Case]![Outcome].Enabled = True
Forms![Case]![Date Requested].SetFocus
DoCmd.Close acForm, "Client", acSaveYes
End If
End If
End If
Cleanup:
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
Thanks