My append query is meant to take some data from public functions and some from a form in order to populate new entries to a maintenance work order database. It seems to work fine until I disable the warnings just before the openquery command. Here is the SQL code.
Code:
INSERT INTO WorkOrders ( Entered_Date, Entered_PC, Entered_User, Type, RequestedBy, Equipment, Description, RequiredCompletion, Status )
SELECT Now() AS Expr1, getPC() AS Expr8, getUser() AS Expr9, [Forms]![NewMWO]![Combo1] AS Expr5, [Forms]![NewMWO]![Combo9] AS Expr6, [Forms]![NewMWO]![Combo17] AS Expr7, [Forms]![NewMWO]![Text26] AS Expr4, [Forms]![NewMWO]![DTPicker3] AS Expr3, 1 AS Expr2;
The code used on the trigger for this query is:
Code:
Private Sub Command40_Click()
Combo1.SetFocus
If Not (Combo1.Text <> "") Then
MsgBox "You must first select a MWO type."
Exit Sub
End If
Combo9.SetFocus
If Not (Combo9.Text <> "") Then
MsgBox "You must enter a requestor."
Exit Sub
End If
Combo11.SetFocus
If Combo11.Text = "" Then
MsgBox "Select a department, followed by location and equipment."
Exit Sub
End If
Combo32.SetFocus
If Combo32.Text = "" Then
MsgBox "Select a location, followed by equipment."
Exit Sub
End If
Combo17.SetFocus
If Combo17.Text = "" Then
MsgBox "Select a piece of equipment."
Exit Sub
End If
Text26.SetFocus
If Text26.Text = "" Then
MsgBox "Enter a description of the problem."
Exit Sub
End If
'DoCmd.SetWarnings (False)
DoCmd.OpenQuery "AddWorkOrder"
'DoCmd.SetWarnings (True)
End Sub
When I uncomment the two setWarning lines I get two entries to the table instead of one. Can anyone see what might be causing this? Thanks in advance for your suggestions!