Need to display a MsgBox if text box is blank before closing a for

S

steve12173

I have a form that has several text boxes but, 4 of them are required. There
is a command button to close the form when completed. I want to include in
the VBA, that when the command button is clicked, if any of the required
fields are blank, a msgbox displays, asking the user to fill in the required
fields. If the fields are not blank, then continue with the close.

Here is the VBA for the command button:

Private Sub Command81_Click()
On Error GoTo Err_Command81_Click


DoCmd.Close

Exit_Command81_Click:
Exit Sub

Err_Command81_Click:
MsgBox Err.Description
Resume Exit_Command81_Click

End Sub


Thanks in advance!
 
A

Alex Dybenko

hi,
write for form's BeforeUpdate event:
If Len(me.Textbox1 & "") = 0 then
Msgbox "Pls enter textbox1!"
cancel=true
exit sub
end if

same for other 4 textboxes

and for Private Sub Command81_Click

me.dirty=false

if not me.dirty then
docmd.close
end if

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top