Okay, I assume your form's Data Entry property is set to No so that you can add and edit records in the same form.
To make it all work, you'll have two combo boxes for the user to select values for limiting the form's recordset. You'll also have a [Show All] command button to show all records. These items will go in the forms header or footer - NOT in the detail section.
Name the combo boxes cboSelEmployeeNumber and cboSelDateWorked. The RowSource of cboSelEmployeeNumber will probably be the table where Employee data is stored. I usually have two columns in my combo box for Employees. And I set ColumnWidths to 0",2.5" so that the actual Employee Number is hidden - the user selects a name. Here's a sample of what the RowSource might look like:
"Select [EmployeeNumber], [Name] From Employees Order by [Name]"
If you have separate first and last name fields, I usually handle it this way:
SELECT Employees.[EmployeeNumber], IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name]) AS Name
FROM Employees
ORDER BY IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name]);
That gives you the format: LastName, FirstName
and sorts by last, first. It also checks to make sure there's a first name since sometimes my databases have group names too, which are always stored in the [Last Name] field.
Okay, now set the row source for cboSelDateWorked. You could use soemthing like:
SELECT DISTINCT tblTimeCard.DateWorked FROM tblTimeCard
ORDER BY tblTimeCard.DateWorked";
That'll give you all valid dates from the tblTimeCard. Note that you could also use a textbox to get the date, but you'll have to check for a valid date yourself - which is why I think its better to use the combo box which has all valid dates in it - and will always return records if there are some for a given employee.
Okay. Make sure you've got both combo boxes renamed before adding any of the following code.
For cboSelEmployeeNumber:
Private Sub cboSelEmployeeNumber_AfterUpdate()
Call prcFormRS
End Sub
For cboSelDateWorked:
Private Sub cboSelDateWorked_AfterUpdate()
Call prcFormRS
End Sub
Add this code to your form's code window:
Private Sub prcFormRS()
'Set RecordSource of form based on cboSelEmployeeNumber and cboSelDateWorked combo boxes
Dim strRSString As String
strRSString = "Select * From [tblTimeCard] Where [EmployeeNumber] <> 0" 'Assuming no Empl # is zero...
If Not IsNull(Me.cboSelEmployeeNumber) Then
strRSString = strRSString & " And [EmployeeNumber] = " & Me.cboSelEmployeeNumber
End If
If Not IsNull(Me.cboSelDateWorked) Then
strRSString = strRSString & " And [DateWorked] = #" & Me.cboSelDateWorked & "#"
End If
Me.RecordSource = strRSString
End Sub
Finally, you'll add your [Show All] button and add the following code to its OnClick Event:
Note: Don't forget to rename your new command button before adding this code.
Private Sub cmdShowAll_Click()
'Clear RecordSet limits and show all records
Me.RecordSource = "Select * From [tblTimeCard]"
Me.cboSelEmployeeNumber = Null
Me.cboSelDateWorked = Null
End Sub
Note: I modified this code from one of my databases as I went along, so I can't guarentee it'll work as written, but you should be able to debug it and get it working.
Good luck - hope this helps...