View Full Version : combobox does not return null when empty?


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

cogent1
06-03-2002, 02:09 PM
Try
Me!cmboCategoryAddTest to refer to fields, rather than Me.etc

Also, put a debug.Print line to see what the combo actually contains.

Or set the default value of the combo to Null or an empty string, whatever is your preference

Happy YN
06-03-2002, 02:45 PM
Thanx!
upon looking at the default value I discovered it was set to 0 . once that was removed it works like a charm.
I had tried with! instead of me. etc to no avail
could do with some reference to read about these different syntax any ideas thanx
A Happy YN!

Pat Hartman
06-04-2002, 04:25 PM
Try this thread:
http://www.access-programmers.co.uk/ubb/Forum1/HTML/005256.html