intermittent invalid use of null mystery

Happy YN

Registered User.
Local time
Today, 05:14
Joined
Jan 27, 2002
Messages
425
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
 
Try checking for the empty string instead of checking for null eg.

If yourCbo = "" Then
MsgBox ("You must select a Category")
Title = "No Category selected!"

HTH

Rich
 
Thanx for quick response but although this eliminates the invalid null message it still bypasses the first message and gives me the message I set for when the textbox is empty?
solved!
Idid what you said but in the second box not the first
thanks again
Happy YN


[This message has been edited by Happy YN (edited 05-29-2002).]
 

Users who are viewing this thread

Back
Top Bottom