S
Shelley
I want to run some code to insert a new record. But, if the PK is
already in the table, I want to stop the code, print an error message,
and exit. Here's what I have so far:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim mySQL As String
DoCmd.GoToRecord , , acNewRec
Me.ReceiptDate = Date
Me.ReleaseDate = DateAdd("m", 6, Format(Now, "mm/dd/yyyy"))
Me.TypeOfCase = "PRR"
mySQL = "INSERT INTO DNLOAD (dnloaded, FIELD001, FIELD008,
FIELD006, FIELD002, FIELD011, FIELD015, FIELD016, FIELD024, FIELD044,
FIELD068) VALUES ('0','VA','" &
[Forms]![Mega-SiteClaimFileReceipt].[SSN] & "','1','" &
[Forms]![Mega-SiteClaimFileReceipt].[FolderNumber] & "','1','1','" &
[Forms]![Mega-SiteClaimFileReceipt].[Shelf Location] & "','" & Date &
"', 'ABC', '1');"
Debug.Print mySQL
DoCmd.RunSQL mySQL, -1
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
If Err.Number = 3022 Then
MsgBox "This Folder is already in the MegaSite!"
Resume Exit_Add_Record_Click
Else
MsgBox Err.Description
Resume Exit_Add_Record_Click
End If
End Sub
Thanks!
Shelley
already in the table, I want to stop the code, print an error message,
and exit. Here's what I have so far:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim mySQL As String
DoCmd.GoToRecord , , acNewRec
Me.ReceiptDate = Date
Me.ReleaseDate = DateAdd("m", 6, Format(Now, "mm/dd/yyyy"))
Me.TypeOfCase = "PRR"
mySQL = "INSERT INTO DNLOAD (dnloaded, FIELD001, FIELD008,
FIELD006, FIELD002, FIELD011, FIELD015, FIELD016, FIELD024, FIELD044,
FIELD068) VALUES ('0','VA','" &
[Forms]![Mega-SiteClaimFileReceipt].[SSN] & "','1','" &
[Forms]![Mega-SiteClaimFileReceipt].[FolderNumber] & "','1','1','" &
[Forms]![Mega-SiteClaimFileReceipt].[Shelf Location] & "','" & Date &
"', 'ABC', '1');"
Debug.Print mySQL
DoCmd.RunSQL mySQL, -1
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
If Err.Number = 3022 Then
MsgBox "This Folder is already in the MegaSite!"
Resume Exit_Add_Record_Click
Else
MsgBox Err.Description
Resume Exit_Add_Record_Click
End If
End Sub
Thanks!
Shelley