Sorry I posted this in the wrong forum to start with!!
I have a combobox and a text box in a form .The user selects a value in the combo and types in a value in the text box before hitting commandbutton. I have code to check both of these boxes are full before a particular action and messages as appropriate when they are empty.
However when I have a blank combobox I get a message stating invalid use of null,BUT if I fill in a value in the TEXTbox then the correct message appears stating that there is nothing selected in the combobox??? THANK YOU!
Here is my code:-
Private Sub cmdAddTest_Click()
On Error GoTo Err_cmdAddTest_Click
Me.Requery
Dim msg As String, Title As String, TxtAdd As String
If IsNull(cmboCategoryaddTest) Then
msg = ("You must select a Category")
Title = "No Category selected!"
TxtAdd = Me.txtTestAdd
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
ElseIf IsNull(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([Test ID], "tests", "[category id] = Forms!frmtestname![cmboCategoryaddTest] AND [test name]='" & Forms!frmtestname![txtTestAdd] & "'")
If textCount > 0 Then
msg = ("ha")
Exit Sub
Else
Dim stDocName As String
stDocName = "appendTest"
DoCmd.OpenQuery stDocName, acNormal, acEdit
End If
End If
Exit_cmdAddTest_Click:
Exit Sub
Err_cmdAddTest_Click:
msgbox Err.Description
Resume Exit_cmdAddTest_Click
End Sub
I have a combobox and a text box in a form .The user selects a value in the combo and types in a value in the text box before hitting commandbutton. I have code to check both of these boxes are full before a particular action and messages as appropriate when they are empty.
However when I have a blank combobox I get a message stating invalid use of null,BUT if I fill in a value in the TEXTbox then the correct message appears stating that there is nothing selected in the combobox??? THANK YOU!
Here is my code:-
Private Sub cmdAddTest_Click()
On Error GoTo Err_cmdAddTest_Click
Me.Requery
Dim msg As String, Title As String, TxtAdd As String
If IsNull(cmboCategoryaddTest) Then
msg = ("You must select a Category")
Title = "No Category selected!"
TxtAdd = Me.txtTestAdd
msgbox msg, vbExclamation + vbOKOnly, Title
Exit Sub
ElseIf IsNull(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([Test ID], "tests", "[category id] = Forms!frmtestname![cmboCategoryaddTest] AND [test name]='" & Forms!frmtestname![txtTestAdd] & "'")
If textCount > 0 Then
msg = ("ha")
Exit Sub
Else
Dim stDocName As String
stDocName = "appendTest"
DoCmd.OpenQuery stDocName, acNormal, acEdit
End If
End If
Exit_cmdAddTest_Click:
Exit Sub
Err_cmdAddTest_Click:
msgbox Err.Description
Resume Exit_cmdAddTest_Click
End Sub