Happy YN
06-03-2002, 09:06 AM
I have a combobox and textbox on a form .The user is supposed to select a vlaue from the combo and type in text into the textbox before hitting the command which runs an append query to append these two values to a table (after checking they do not already exist)
However when nothing is selected in the combo it seems to bypass my code and run on to examine whether there is something in the textbox, If there is it will go ahead with the append !
What am i doing wrong?
Here is my code I would really appreciate help on this! THANX!
Private Sub cmdAddTest_Click()
On Error GoTo Err_cmdAddTest_Click
Me.Requery
Dim msg As String, Title As String, TxtAdd As String
If IsNull(Me.cmboCategoryaddTest) Then
'If Me.cmboCategoryaddTest = "" Then -HAVE TRIED THIS BUT NO GOOD
msg = ("You must select a Category")
Title = "No Category selected!"
TxtAdd = Me.txtTestAdd
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
ElseIf IsNull(txtTestAdd) Then
' "Have tried this but no good" ElseIf Me.txtTestAdd = "" Then
msg = ("You must supply a test name")
Title = "No test name supplied!"
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
Else
Dim textCount As Byte
textCount = Dcount("*", "dcountTests")
If textCount > 0 Then
msg = ("Test already exists for this category")
Title = "Duplication error!"
msgbox msg, vbOKOnly + vbExclamation, Title
Me.txtTestAdd = ""
Exit Sub
Else
Dim stDocName As String
stDocName = "appendTest"
DoCmd.OpenQuery stDocName, acNormal, acEdit
msg = (Me.txtTestAdd & " has been succesfully added to " & Me.cmboCategoryaddTest.Column(1))
Title = "Test added"
msgbox msg, vbOKOnly, Title
End If
End If
Exit_cmdAddTest_Click:
Exit Sub
Err_cmdAddTest_Click:
msgbox Err.Description
Resume Exit_cmdAddTest_Click
End Sub
However when nothing is selected in the combo it seems to bypass my code and run on to examine whether there is something in the textbox, If there is it will go ahead with the append !
What am i doing wrong?
Here is my code I would really appreciate help on this! THANX!
Private Sub cmdAddTest_Click()
On Error GoTo Err_cmdAddTest_Click
Me.Requery
Dim msg As String, Title As String, TxtAdd As String
If IsNull(Me.cmboCategoryaddTest) Then
'If Me.cmboCategoryaddTest = "" Then -HAVE TRIED THIS BUT NO GOOD
msg = ("You must select a Category")
Title = "No Category selected!"
TxtAdd = Me.txtTestAdd
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
ElseIf IsNull(txtTestAdd) Then
' "Have tried this but no good" ElseIf Me.txtTestAdd = "" Then
msg = ("You must supply a test name")
Title = "No test name supplied!"
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
Else
Dim textCount As Byte
textCount = Dcount("*", "dcountTests")
If textCount > 0 Then
msg = ("Test already exists for this category")
Title = "Duplication error!"
msgbox msg, vbOKOnly + vbExclamation, Title
Me.txtTestAdd = ""
Exit Sub
Else
Dim stDocName As String
stDocName = "appendTest"
DoCmd.OpenQuery stDocName, acNormal, acEdit
msg = (Me.txtTestAdd & " has been succesfully added to " & Me.cmboCategoryaddTest.Column(1))
Title = "Test added"
msgbox msg, vbOKOnly, Title
End If
End If
Exit_cmdAddTest_Click:
Exit Sub
Err_cmdAddTest_Click:
msgbox Err.Description
Resume Exit_cmdAddTest_Click
End Sub