Adding a new Required field

R

Ramesh

Can i add a new field to my table such that i enforce a Required condition
on it? I cant do this in the table design cos the field will be blank till
date. Only the records henceforth should have a mandatory entry in this
field. Is there a way i can set this up in the Form?

Thanks
Ramesh
 
G

Guest

Hi Ramesh

You could use a messages box to tell users that they need to input data on a
form.
If the field in the table is call "TheField" use something like this on
your form.

If you also use SetFocus in the code you will take the user back to the
field until data is entered. - BUT you need to think about this - is data
"always" needed, if not don't use the SetFocus line in the code.


Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TheField) Then

MsgBox "You must add data here"

Me.TheField.SetFocus

Cancel = True

End If

End Sub

Hope this helps
 
R

Ramesh

Thanks .. that helped. I need to use it only on fields which should not go
without data.

Ramesh
 
J

John W. Vinson

Can i add a new field to my table such that i enforce a Required condition
on it? I cant do this in the table design cos the field will be blank till
date. Only the records henceforth should have a mandatory entry in this
field. Is there a way i can set this up in the Form?

Wayne's suggestion should do most of the job for you. If you really want to
make the field required, thereby prohibiting users from "going around" your
form and editing records directly in the table, you'll need to create a new,
empty table with the required field specified, and populate it using an Append
query from your existing table. You'll need to use some sort of calculated
field to fill the required field with some reasonable value.

John W. Vinson [MVP]
 

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