Turning off Error Messages

D

Diana

Hello,

I am trying to turn off an error message '2051'.
I am appending data from excel to aceess to a table which
has a composite primary key. If an user tries to import
the same excel data twice Access gives an error because
of the potential dublicate key problems. I would like to
turn off the error message and I tried different
permutations of the procedure below and nothing is
working out right. Thank you for your time and help:
-----------------------------------------------
Private Sub cmdExport_Click()

Call macImport

End Sub
------------------------------------
Function macImport()

On Error GoTo macImport_Err

DoCmd.TransferSpreadsheet acImport,
8, "Tracking", "C:\Documents and
Settings\user\Desktop\PaperTracking.xls", True, "Export"
Beep
MsgBox "File Transfered.", vbInformation, ""
DoCmd.Close acForm, "Export"
DoCmd.OpenForm "Main", acNormal, "", "", , acNormal

DoCmd.SetWarnings True
macImport_Exit:
Exit Function

macImport_Err:
DoCmd.SetWarnings False
MsgBox "The records already exist in your table"

Resume macImport_Exit

End Function
 
M

Mike Painter

Turn the errors off before the error is committed
Diana said:
Hello,

I am trying to turn off an error message '2051'.
I am appending data from excel to aceess to a table which
has a composite primary key. If an user tries to import
the same excel data twice Access gives an error because
of the potential dublicate key problems. I would like to
turn off the error message and I tried different
permutations of the procedure below and nothing is
working out right. Thank you for your time and help:
-----------------------------------------------
Private Sub cmdExport_Click()

Call macImport

End Sub
DoCmd.SetWarnings False
 
J

John Vinson

Hello,

I am trying to turn off an error message '2051'.

I'd suggest explicitly trapping that particular error:


macImport_Exit:
Exit Function

macImport_Err:
If Err.Number = 2051 Then
DoCmd.SetWarnings False
MsgBox "The records already exist in your table"
Else
MsgBox "Error " & Err.Num & " in macImport:" & vbCrLf _
& Err.Description
End If
Resume macImport_Exit

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top