I set up a table called tblEmployeeTimecard and a form of the same table to allow the user to search for an employee name and enter a date in respective text fields. Seek is suppose to bring up any existing record that matches the name and date. If it doesn't find a match, it goes to a new record.
I added the multi-column index as I should. When it doesn't find a match, it does go to a new record. So SEEK seems to be working. But when it FINDS a match, nothing happens. My form is still at the first record. What am I doing wrong? How can I display the record that matches the user's entry? Here's what I have:
Private Sub txtDate_AfterUpdate()
Dim dbs As Database
Dim rst As Recordset
If IsNull([txtDate]) = False Then
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblEmployeeTimecard", dbOpenTable)
rst.Index = "Employee_ID_Date"
rst.Seek "=", txtEmployee_ID, txtDate
If rst.NoMatch Then
'Adds new record if no matching Employee ID and Date in tblEmployeeTimecard
DoCmd.GoToRecord , , acNewRec
End If
rst.Close
Set dbs = Nothing
End If
End Sub
I added the multi-column index as I should. When it doesn't find a match, it does go to a new record. So SEEK seems to be working. But when it FINDS a match, nothing happens. My form is still at the first record. What am I doing wrong? How can I display the record that matches the user's entry? Here's what I have:
Private Sub txtDate_AfterUpdate()
Dim dbs As Database
Dim rst As Recordset
If IsNull([txtDate]) = False Then
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblEmployeeTimecard", dbOpenTable)
rst.Index = "Employee_ID_Date"
rst.Seek "=", txtEmployee_ID, txtDate
If rst.NoMatch Then
'Adds new record if no matching Employee ID and Date in tblEmployeeTimecard
DoCmd.GoToRecord , , acNewRec
End If
rst.Close
Set dbs = Nothing
End If
End Sub