Okay, thanks. That is what we need.
Here is what I would suggest.
Take the Where Clause out of your query.
Instead of opening the form from the menu, create a new form and have the
menu open the new form. It will open your existing form. Put a text box on
the new form for the user to enter the initials. It would be a good idea to
check to make sure the intitials are actually in the table before opening the
form. You can do that in the After Update event of the text box.
If IsNull(DLookup("[staff]","tbl_entries]","[staff] = """ &
Me.txtInitials & """") Then
MsgBox "Select A Valid Staff Memember or " & vbNewLine & _
"Leave Blank to add a new member", vbInformation, _
"Staff Member Not Found"
End If
Also on the form, add a command button to open the form to the selected
member or a blank for to allow a new member to be added and use the Click
event:
If Me.txtInitials = Null & vbNullstring Then
DoCmd.OpenForm "frm_entry_for_one_member", , , , acFormAdd
Else
DoCmd.OpenForm "frm_entry_for_one_member", , , [staff] =
Me.txtInitials, acFormEdit
End If
Docmd.Close acForm, Me.Name, acSaveNo
That way, it will open to the valid staff member if it exist and open a
blank for to enter a new member if not.
--
Dave Hargis, Microsoft Access MVP
GA said:
The control on the form is "staff".
[Service Initials] is the parameter that the query 'asks' for.
The form is opened with a button on a menu form in which I haven't set
any criteria -
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm_entry_for_one_member"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub
GA
That's helpful, but you missed an important part.
Please post the code where you open the form. I need to know how it knows
which staff member to show.
Is [Service Initials] a control on the form?
--
Dave Hargis, Microsoft Access MVP
GA said:
Thanks for the response.
I have my form based on a parameter query which is -
SELECT tbl_entries.date, tbl_entries.staff, tbl_entries.working
FROM tbl_entries
WHERE (((tbl_entries.staff)=[Service Initials]))
ORDER BY tbl_entries.date;
The form opens to show all existing records which are restricted to a
single member by virtue of coming from the query.
I thought that in the on current event of the form I could do
something like -
if Me.NewRecord=true then Me.staff = [Service Initials]
but it doesn't work.