Required Field

S

StephanieH

I'm trying to use the following example to make a field required:
If IsNull(Me!YourRequiredControl) Then
MsgBox "Please fill in <YourRequiredControl>"
Cancel = True
Me!YourRequiredControl.SetFocus
End If

My field name is [Required by]

I've tried replacing YourRequiredControl with Required by, [Required by],
"Required by" and Required_by but none of these seem to work. How do I get
it to recognize the field name if it includes spaces?
 
M

Maurice

Do you know which [required by] isn't working. Is it the first one or the one
in the messagebox.

me.[required by] should do the job. In the messagebox you are referring to
me.[required by as well] but that will only show the content of the field. I
think you should refer to the name of the control to get the message to the
user.

If that's what you are looking for try this:

MsgBox "Please fill in " & me.[required by]

hth
 
F

fredg

I'm trying to use the following example to make a field required:
If IsNull(Me!YourRequiredControl) Then
MsgBox "Please fill in <YourRequiredControl>"
Cancel = True
Me!YourRequiredControl.SetFocus
End If

My field name is [Required by]

I've tried replacing YourRequiredControl with Required by, [Required by],
"Required by" and Required_by but none of these seem to work. How do I get
it to recognize the field name if it includes spaces?

You've given us nice information but .... you don't tell us what event
you placed this code in. :-(

A field name with spaces in it MUST be enclosed within brackets, not
quotes nor underscore (a very good reason to NOT include spaces in
field names).

Use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me![Required by]) Then
MsgBox "Please fill in <YourRequiredControl>"
Cancel = True
Me![Required by].SetFocus
End If
 
S

StephanieH

Sorry, yes it was in Before Updates
I try to avoid spaces in field names, but didn't design this one originally.
However, when you mentioned that, I went back and remove the spaces from the
field names.
Now that I'm getting past that piece, it debugs at the Setfocus line. I get
the error
Runtime error 438. Object doesn't support this property or method.
I can comment it out and it runs fine, so do I need that piece? Is it
creating an issue behind the scenes that I'm not aware of?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!OriginalLienType) Then
MsgBox "Please fill in <OriginalLienType>"
Cancel = True
' Me!OriginalLienType.SetFocus
End If
If IsNull(Me!ReviewedBy) Then
MsgBox "Please fill in <Reviewedby>"
Cancel = True
' Me!Reviewedby.SetFocus
End If

End Sub



fredg said:
I'm trying to use the following example to make a field required:
If IsNull(Me!YourRequiredControl) Then
MsgBox "Please fill in <YourRequiredControl>"
Cancel = True
Me!YourRequiredControl.SetFocus
End If

My field name is [Required by]

I've tried replacing YourRequiredControl with Required by, [Required by],
"Required by" and Required_by but none of these seem to work. How do I get
it to recognize the field name if it includes spaces?

You've given us nice information but .... you don't tell us what event
you placed this code in. :-(

A field name with spaces in it MUST be enclosed within brackets, not
quotes nor underscore (a very good reason to NOT include spaces in
field names).

Use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me![Required by]) Then
MsgBox "Please fill in <YourRequiredControl>"
Cancel = True
Me![Required by].SetFocus
End If
 

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