2 combo boxes to add new record

mcgooie

Registered User.
Local time
Today, 20:52
Joined
Sep 12, 2006
Messages
11
i have 2 combo boxes on a form and a button to add a new record in a table. i am trying to add code so that if either of the boxes is 'null' that an error message displays and the code ends so that a partial record isnt entered into the table. i think the solution is adding a line somewhere to my code but im not sure where. Here is the code i have for just one of the boxes to get it working correctly:

Code:
Private Sub Command31_Click()
On Error GoTo Err_Command31_Click
If IsNull(Me.Combo14) Then
MsgBox ("invalid selection made")
End If

    DoCmd.GoToRecord , , acNewRec

Exit_Command31_Click:
    Exit Sub

Err_Command31_Click:
    MsgBox Err.Description
    Resume Exit_Command31_Click
    
End Sub

This code gives me the error message, ive tried putting in end sub/exit sub before and after the 'end if' but each time the record is added to the table.
Can someone tell me how to end the procedure after the if statement if its condition is true?
 
Code:
Private Sub Command31_Click()
On Error GoTo Err_Command31_Click
[COLOR="Blue"]If IsNull(Me.Combo14) or Me.Combo14 = "" Then[/COLOR]
MsgBox [COLOR="Blue"]"invalid selection made"[/COLOR]
[COLOR="Blue"]Me.Undo ' This removes all data from the form.[/COLOR]

[COLOR="Blue"]Else[/COLOR]

 DoCmd.GoToRecord , , acNewRec

[COLOR="Blue"]End If [/COLOR]

Exit_Command31_Click:
    Exit Sub

Err_Command31_Click:
    MsgBox Err.Description
    Resume Exit_Command31_Click
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom