I have a table with has three fields as primary keys - to prevent duplicate information being input.
I have a form that uses an append query to add data to the table.
If the user tries to input a different dollar amount to an already existing Program/State/Date (the three primary keys) it will not append due to "key violations"
Okay so far.
Since I don't want the user to have to click okay to all the "we are about to append etc." messages that occur I have the following in my code:
docmd.setwarnings False (then reset to True at the end)
msgbox "Record Added"
Since the user doesn't see the message stating that the records were not appended and only sees the "record added", they are not aware that there is a problem.
So I took out the docmd.setwarnings False and included an "on error" event for the form that "intercepts" these messages -
So I now have error #8057 isolated and my message appears that they have attempted to make a duplicate entry.
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 8057
MsgBox "You already have dollars associated with this"
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
However, now the user has to still click off on the messages that they are about to append...... AND my message box still lets tells them "Record Added". I've got something out of sync here. Any thoughts? My main code follows:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click
If IsNull(Me![txtPlan].Value) Then Me![txtPlan].Value = 0
If IsNull(Me![txtCE].Value) Then Me![txtPlan].Value = 0
If IsNull(Me![txtPlanDate].Value) Or Me![txtPlanDate].Value = "" Then
MsgBox "Please Select a Month", vbOKOnly
[lstMnth].SetFocus
Exit Sub
End If
If Me![txtPlan].Value = 0 And Me![txtCE].Value = 0 Then
MsgBox "Please input a CE or Plan amount", vbOKOnly
Exit Sub
End If
'DoCmd.SetWarnings False
If Me![txtPlan] <> 0 And Not IsNull(Me![txtPlan]) Then
DoCmd.OpenQuery "qryAppendtblTarget", acViewNormal, acEdit
Forms![frmInputTargets]![subfrmtblTarget].Requery
MsgBox "Record Added To Plan", vbOKOnly
End If
If Me![txtCE] <> 0 Then
DoCmd.OpenQuery "qryAppendtblCE", acViewNormal, acEdit
Forms![frmInputTargets]![subfrmtblCE].Requery
MsgBox "Record Added To CE", vbOKOnly
End If
'DoCmd.SetWarnings True
Exit_cmdAddRecord_Click:
Exit Sub
Err_cmdAddRecord_Click:
MsgBox "Error number: " & Err.Number & " - " & Err.Description
Resume Exit_cmdAddRecord_Click
End Sub
I have a form that uses an append query to add data to the table.
If the user tries to input a different dollar amount to an already existing Program/State/Date (the three primary keys) it will not append due to "key violations"
Okay so far.
Since I don't want the user to have to click okay to all the "we are about to append etc." messages that occur I have the following in my code:
docmd.setwarnings False (then reset to True at the end)
msgbox "Record Added"
Since the user doesn't see the message stating that the records were not appended and only sees the "record added", they are not aware that there is a problem.
So I took out the docmd.setwarnings False and included an "on error" event for the form that "intercepts" these messages -
So I now have error #8057 isolated and my message appears that they have attempted to make a duplicate entry.
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 8057
MsgBox "You already have dollars associated with this"
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
However, now the user has to still click off on the messages that they are about to append...... AND my message box still lets tells them "Record Added". I've got something out of sync here. Any thoughts? My main code follows:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click
If IsNull(Me![txtPlan].Value) Then Me![txtPlan].Value = 0
If IsNull(Me![txtCE].Value) Then Me![txtPlan].Value = 0
If IsNull(Me![txtPlanDate].Value) Or Me![txtPlanDate].Value = "" Then
MsgBox "Please Select a Month", vbOKOnly
[lstMnth].SetFocus
Exit Sub
End If
If Me![txtPlan].Value = 0 And Me![txtCE].Value = 0 Then
MsgBox "Please input a CE or Plan amount", vbOKOnly
Exit Sub
End If
'DoCmd.SetWarnings False
If Me![txtPlan] <> 0 And Not IsNull(Me![txtPlan]) Then
DoCmd.OpenQuery "qryAppendtblTarget", acViewNormal, acEdit
Forms![frmInputTargets]![subfrmtblTarget].Requery
MsgBox "Record Added To Plan", vbOKOnly
End If
If Me![txtCE] <> 0 Then
DoCmd.OpenQuery "qryAppendtblCE", acViewNormal, acEdit
Forms![frmInputTargets]![subfrmtblCE].Requery
MsgBox "Record Added To CE", vbOKOnly
End If
'DoCmd.SetWarnings True
Exit_cmdAddRecord_Click:
Exit Sub
Err_cmdAddRecord_Click:
MsgBox "Error number: " & Err.Number & " - " & Err.Description
Resume Exit_cmdAddRecord_Click
End Sub