combo box: access can't read its value when ....? (1 Viewer)

Jon.N

Registered User.
Local time
Today, 00:11
Joined
Nov 24, 2000
Messages
43
I have found an interesting occurrence where Access doesn't seem to be able to read a null value in a combo box.

The operation is: one makes a selection in a combo box and then clicks a button to open a form and find a record based on the value in the combo box.

However if someone opens the combo box list and clicks away from the combo box, say on the form background the list closes and displays an empty field. Then if the button is clicked everything goes wrong because the form opens but there is no record to display.

I have tried to trap this ‘bug’ a couple of ways:
>> Code like If IsNull (combo.value) then ... behind several events like the combo box’s After Update Event or Lost Focus Event, even the On Click Event of the form’s detail section.
>> Using <>"" in the combo boxes validation rule doesn’t work either.

The any of the above traps work if one: opens the combo box, selects a value and then blocks and deletes the value, but to repeat myself definitely not if one clicks away before making a selection.

Has anyone come across this before? Any ideas as always are gratefully received.
 

indesisiv

Access - What's that?
Local time
Today, 00:11
Joined
Jun 13, 2002
Messages
265
i use something like
Code:
Private Sub Command2_Click()
If IsNull(Me.Combo0) Then
    With Me.Combo0
        .SetFocus
        .Dropdown
    End With

End If
End Sub

Hope that helps
 

Jon.N

Registered User.
Local time
Today, 00:11
Joined
Nov 24, 2000
Messages
43
I think I have answered my own question

Many thanks for this indesisiv. The code you suggest is very similar to the code I already had (only neater) but the code wasn't working. I hadn't realised I could use IsNull (Me.comb) I always thought one had use the .Value also, i.e. [IsNull (Me.combo.Value)].

I have now found out why, or rather why I think my code wasn't working. Somewhere in the bowels of my code there is a point where my combo box is given the "" (open/close speech marks) value: Me.combo.Value = "". If I am correct IsNull or Null is different to "". Can anyone confirm this please?
:)
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:11
Joined
Feb 19, 2002
Messages
43,519
Yes, null is different from "" which is called a zero-length string.
 

Users who are viewing this thread

Top Bottom