Manditory fields

D

Dan @BCBS

I had to make a few of the values on a form required, so I unchecked the
allow nulls in the SQL db table that they are linked to, refreshed and
relinked the tables, no problems.. I've recreated the queries that the form
is made from etc.

Everything I do still allows the user to close the form without having to
enter a value.

I'd like to code a command button to require the user to enter a value,
could some one please help.

This code asks the user to enter data but it does not stop them from closing
it without doing so..

Suggestions..
 
D

Dale Fye

Dan,

Check out the forms BeforeUpdate event. This event has a Cancel parameter
that will allow you to cancel the update if a field is blank. Something like:

Public sub Form_BeforeUpdate(Cancel as integer)

If LEN(me.txt_some_Control & "") = 0 then
msgbox "Enter some value in this control"
me.txt_Some_Control.setfocus
Cancel = true
elseif LEN(me.txt_some_other_control & "") = 0 then
msgbox "enter a value in this other control"
me.txt_some_other_control.setfocus
Cancel = true
endif

end sub
 

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

Top