troubleshooting Question

Access 2010 Error Handling

Avatar of UbiqutyDegins
UbiqutyDegins asked on
Microsoft OfficeMicrosoft Access
1 Comment1 Solution341 ViewsLast Modified:
I get an Error when trying to add error handing.

I am trying to to add Error handling to my code.  I would like a MsgBox to pop up reminding the user to make sure all fields have been entered before adding the record to the table.

I keep getting "Invaild use of Null" as an error.

Private Sub cmdUpdatePart_Click()
On Error GoTo Err_UpdatePart_Click
Dim db As Database
Dim updatePart As String
Dim part As String
Dim man As String
Dim des As String
Dim ce As String
Dim wj As String
Dim ss As String
Dim he As String
Dim pack As String

Set db = CurrentDb

If ([Forms]![frmMain]![subfrmProdSpecs].[Form]![txtPartNum] = Null) Then
    MsgBox "You must enter a Part Number", vbOKOnly
ElseIf ([Forms]![frmMain]![subfrmProdSpecs].[Form]![txtDescription] = Null) Then
    MsgBox "Please enter a Description of the part.", vbOKOnly
End If

part = [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtPartNum]
man = [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtManufacturer]
des = [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtDescription]
ce = "I:\Product Specifications\Cold End\" & [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtCE_Packet]
wj = "I:\Product Specifications\Water Jet\" & [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtWJ_Packet]
ss = "I:\Product Specifications\Silk Screen\" & [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtSS_Packet]
he = "I:\Product Specifications\Hot End\" & [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtHE_Packet]
pack = "I:\Product Specifications\Packaging\" & [Forms]![frmMain]![subfrmProdSpecs].[Form]![txtPack_Packet]

updatePart = "INSERT INTO tblParts VALUES ('" & part & "', '" & man & "', '" & des & "', '" & ce & "', '" & wj & "', '" & ss & "', '" & he & "', '" & pack & "')"

DoCmd.RunSQL (updatePart)

Err_UpdatePart_Click:
    If ([Forms]![frmMain]![subfrmProdSpecs].[Form]![txtPartNum] = Null) Then
        MsgBox "You must enter a Part Number", vbOKOnly
    ElseIf ([Forms]![frmMain]![subfrmProdSpecs].[Form]![txtDescription] = Null) Then
        MsgBox "Please enter a Description of the part.", vbOKOnly
    Else: MsgBox Err.Description
    End If
    Resume Exit_UpdatePart_Click
    
Exit_UpdatePart_Click:
    Exit Sub

End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros