Combo boxes and evaluating null fields

mackyrm

Registered User.
Local time
Yesterday, 21:32
Joined
Oct 5, 2006
Messages
57
I have a database form with a combo box. I want to ascertain if data has been entered into this box before closing the form.

My code below only works when data has been entered and deleted in the combo field, but not on records where this particualr field has never populated.

Any thoughts on this appreciated...


------------------


Private Sub btnClose_Click()

Dim strEnquiryMissing As String
On Error GoTo Err_btnClose_Click

DoCmd.RunCommand acCmdSaveRecord

cmbEnquiryType.SetFocus

If IsNull(Me!cmbEnquiryType) Then

MsgBox ("You must provide an enquiry category for this record")

Else
Forms![frmsmclient]![sbfrmCommentList].Requery
Forms![frmsmclientb3]![sbfrmCommentList].Requery
DoCmd.Close

End If

Exit_btnClose_Click:
Exit Sub

Err_btnClose_Click:

DoCmd.Close
End Sub
 
use unload event instead, as you can cancel that, and stop the form closing

so in the form unload event

if nz(combobox,0)=0 then
'(or use nz(combobox,"")="" if its a string)
msgbox("cannot close Yet")
cancel = vbcancel
end if
 
Amended the original code replacing ISNULL with NZ. The NZ function (never used this before) worked a treat.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom