View Full Version : Combo boxes and evaluating null fields


mackyrm
12-12-2008, 12:57 AM
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

gemma-the-husky
12-12-2008, 04:13 AM
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

mackyrm
12-15-2008, 03:30 AM
Amended the original code replacing ISNULL with NZ. The NZ function (never used this before) worked a treat.

Thanks!