Combo Box Validation

Carrie

Registered User.
Local time
Today, 16:01
Joined
Jan 8, 2003
Messages
36
Hi

I've been looking on the forum to try and find my answer but am struggling to find anything!

I have a combo box which I am validating by using IsNull. This works fine untill someone fills the combo box and then decides to delete it leaving the combo box empty again. My IsNull then does not work. Have tried putting in "" too but this does not seem to work either

Below is my example
If IsNull(Me.cboInt) Or [cboInt] = "" Then
MsgBox "You need to choose an interviewer first!", vbCritical
Me.cboInt.SetFocus
End If

I know this must be simple! Can anyone point me in the right direction please?
 
Your code looks okay. Are you using the Forms BeforeUpdate event to ensure the combo box is not empty?
 
Hi

Thanks for your response.

No I'm not using the before update event.

I'm using it on the On Got Focus of a command button.

I'm basically trying to make the user enter a name before they run a report (the report is based on whatever name they type in in the combo box cboInt.)

I have just had a play at putting the code in the before update on the form but this has not made any difference.

Any more comments/thoughts would be very helpful!

Carrie
 
Not that this is much help but,

I just tried your code in the got focus event and also the mousemove event of a command button. It worked fine in Access 2000 even when I populated the combo and then deleted the contents. Initially I had the combo limited to list but I removed that thinking maybe they were leaving a blank space in the combo. Still worked ok.

Perhaps you need to check some other areas before blaming this code...... ???

Told ya it wouldnt be much help!!
 
Hi

Thanks JrJr - your comments did help.

Meant I knew it was something within my code!

Had another quick play and it works if I change the code from below

If IsNull(Me.cboInt) Or [cboInt] = "" Then
MsgBox "You need to choose an interviewer first!", vbCritical
Me.cboInt.SetFocus
End If

To

If IsNull(Me.cboInt) Or (Me.cboInt) = "" Then
MsgBox "You need to choose an interviewer first!", vbCritical
Me.cboInt.SetFocus
End If

Simple - but has solved my problem!

Thanks

Carrie
 
What version of Access are you using? It's odd that it worked ok for me and not for you!!
 
I've got Access 97!

The code I posted earlier still didn't work!!
But I had a think and tried this code instead

If IsNull(Me.cboInt) Or (Me.cboInt.[Column](1)) = "" Then
MsgBox "You need to choose an interviewer first!", vbCritical
Me.cboInt.SetFocus
End If

Leading me to think that it was something to do with the data type.
Combo box based on two fields - one number(0) and one text (1). I think this is why it was not working.

Thanks
Carrie
 
That is it then. The combo I used was based on just one field.

Glad it worked out for you.

Cheers!!
 

Users who are viewing this thread

Back
Top Bottom