Hi. Could you post the code you're currently using so we can what you've attempted and help you to fix it up?
This is the code connected to the command button on the form
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
Dim stDocName As String
stDocName = "permit update for issued permits"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox " A live permit already exists, deactivate if necessary", vbOKOnly, "pleb head"
Resume Exit_Command24_Click
End Sub
The next bit is the query
"INSERT INTO [Permit details] ( Permit_user_id, Permit_decsion, Permit_issue_no, Permit_date_issued )
SELECT DISTINCT CStr(Forms![select staff form]![staff details1f].form!emp_id) AS Expr1, 1 AS Expr2, IIf([MaxOfPermit_issue_no] Is Null,1,[MaxOfPermit_issue_no]+1) AS Expr5, Date() AS Expr3
FROM ([staff details] LEFT JOIN [max permit issue no] ON [staff details].emp_id = [max permit issue no].Permit_user_id) LEFT JOIN livepermits ON [staff details].emp_id = livepermits.Permit_user_id
WHERE (((livepermits.Permit_user_id) Is Null) AND (([staff details].emp_id)=[Forms]![select staff form]![staff details1f].[form]![emp_id]));"
The code is running an append query. In that query I have a subquery that pulls out all "live" permits from the Permits Table. The record will only be appended emp_id does not exist in the "live permits" query. At the moment i have the "action queries" confirm on and all that happens is the message "0 records appended appears".
What I really want to do is run the "live permits" query first and if the "emp_id" exists in this query place a msgbox on the screen that states "This person already has a permit" and then not run the append query. But if it doesn't exist to run the append query and give the user the message "Permit created"
Thanks
Helena