Change Required Field Property in Table

J

Jonas

I am trying to change the required field property in for a field in an
existing table based on a value in a field in my form. I am using the
BeforeUpdate event.

Here is what I have so far:

tables!tblPayments!tblPaymentsDateWritten.Required = False

When the conditions are met, I get a message that says, "Runtime error
'424' Object Required." Can the Required property of the field be
altered from a form? If so, How can I do it?
 
S

Stuart McCall

Jonas said:
I am trying to change the required field property in for a field in an
existing table based on a value in a field in my form. I am using the
BeforeUpdate event.

Here is what I have so far:

tables!tblPayments!tblPaymentsDateWritten.Required = False

When the conditions are met, I get a message that says, "Runtime error
'424' Object Required." Can the Required property of the field be
altered from a form? If so, How can I do it?

CurrentDb.TableDefs!tblPayments!tblPaymentsDateWritten.Required = False

ought to do it.
 
J

Jonas

CurrentDb.TableDefs!tblPayments!tblPaymentsDateWritten.Required = False

ought to do it.

Thanks for the response. I get a message that says that I can not
modify the table structure because another user has the table open.
It looks like I am just going to have to check for null values before
saving. Maybe it is better to create a message box that says which
fields are missing data anyway.
 
J

John W. Vinson

I am trying to change the required field property in for a field in an
existing table based on a value in a field in my form. I am using the
BeforeUpdate event.

Here is what I have so far:

tables!tblPayments!tblPaymentsDateWritten.Required = False

When the conditions are met, I get a message that says, "Runtime error
'424' Object Required." Can the Required property of the field be
altered from a form? If so, How can I do it?

This is pretty clearly the wrong way to go about it!

The Required property of a field in the table applies to *EVERY SINGLE RECORD*
in the table: the field is either required to be present in all records... or
not. This property cannot be dependent on some other value, and cannot be set
dynamically from a form (especially not in a split database, which you should
be using).

I suspect you want to check the *data* in the form controls, in the Form's
BeforeUpdate event, and detect at that point whether the field is needed or
not.
 
S

Stuart McCall

CurrentDb.TableDefs!tblPayments!tblPaymentsDateWritten.Required = False

ought to do it.
Thanks for the response. I get a message that says that I can not
modify the table structure because another user has the table open.
It looks like I am just going to have to check for null values before
saving. Maybe it is better to create a message box that says which
fields are missing data anyway.

Ah. If that's your aim then you should take John Vinson's advice. I thought
you were maybe building a form wizard or something (I've done lots of work
like that, so that's how it tends to look to me).
 

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