Turning off a required field on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In my DB, I have a field that is defined as required in the table; now, what
I would like to do is to make it NOT required on some forms, while it can be
on others. The issue is that even though users are not seeing it on some
forms, they are given an error when they are trying to move on to the next
record.

Any help would be greatly appreciated.

Thanks,
Luther
 
If the field in your table is marked as Required, Access will always demand
that it has a value. Since this is not what you want, you must set the
field's Required property to No in the table.

In the forms where you do want to force an entry, use the BeforeUpdate event
of the *form* to do that. The event procedure will look something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[NameOfYourFieldHere]) Then
Cancel = True
MsgBox "Must enter a value."
End If
End Sub
 
Thank you !!!!

Allen Browne said:
If the field in your table is marked as Required, Access will always demand
that it has a value. Since this is not what you want, you must set the
field's Required property to No in the table.

In the forms where you do want to force an entry, use the BeforeUpdate event
of the *form* to do that. The event procedure will look something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[NameOfYourFieldHere]) Then
Cancel = True
MsgBox "Must enter a value."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Luther said:
In my DB, I have a field that is defined as required in the table; now,
what
I would like to do is to make it NOT required on some forms, while it can
be
on others. The issue is that even though users are not seeing it on some
forms, they are given an error when they are trying to move on to the next
record.

Any help would be greatly appreciated.

Thanks,
Luther
 
Allen,

If I wanted to do this for more than one field, can you give an example of
how I would I code the event, please?

Thanks,
Luther

Allen Browne said:
If the field in your table is marked as Required, Access will always demand
that it has a value. Since this is not what you want, you must set the
field's Required property to No in the table.

In the forms where you do want to force an entry, use the BeforeUpdate event
of the *form* to do that. The event procedure will look something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[NameOfYourFieldHere]) Then
Cancel = True
MsgBox "Must enter a value."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Luther said:
In my DB, I have a field that is defined as required in the table; now,
what
I would like to do is to make it NOT required on some forms, while it can
be
on others. The issue is that even though users are not seeing it on some
forms, they are given an error when they are trying to move on to the next
record.

Any help would be greatly appreciated.

Thanks,
Luther
 
This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.Surname) Then
Cancel = True
strMsg = strMsg & "Surname required." & vbCrLf
End If

If IsNull(Me.City) Then
Cancel = True
strMsg = strMsg & "City required." & vbCrLf
End If

'etc for other fields.

If Cancel Then
strMsg = strMsg & vbCrLf & "Correct the entry, or press Esc to
undo."
MsgBox strMsg
End If
End Sub


--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Luther said:
Allen,

If I wanted to do this for more than one field, can you give an example of
how I would I code the event, please?

Thanks,
Luther

Allen Browne said:
If the field in your table is marked as Required, Access will always
demand
that it has a value. Since this is not what you want, you must set the
field's Required property to No in the table.

In the forms where you do want to force an entry, use the BeforeUpdate
event
of the *form* to do that. The event procedure will look something like
this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[NameOfYourFieldHere]) Then
Cancel = True
MsgBox "Must enter a value."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Luther said:
In my DB, I have a field that is defined as required in the table; now,
what
I would like to do is to make it NOT required on some forms, while it
can
be
on others. The issue is that even though users are not seeing it on
some
forms, they are given an error when they are trying to move on to the
next
record.

Any help would be greatly appreciated.

Thanks,
Luther
 
Back
Top