Field on form required depending on value in another field

L

Laura C.

Hi,

I've seen several useful for suggestions for how to get a field in a form to
be required based on the value in another field, but none of the code
provided is working for me. I think it may have something to do with the fact
that the "if" statement involves text -- I've been using the asterisk to
stand in for the rest of the string (i.e., only the first few words need to
be present to make the other field required). But do I want an "=" sign here,
or the expression "Is Like"?

I'm also wondering if part of the problem lies with the fact that the field
that I want to be required under certain conditions is a list box in which I
have generated the values from within the form (i.e., they are not being
called up from a table somewhere, also the values entered do GO INTO my
table).

Here is the code I've tried inserting under "BeforeUpdate" for the form:

If Me.Action = "Sales/purchases*" Then
If IsNull(Me.Event) = True Then
MsgBox "You must enter 'Purchase' or 'Redeem' under 'Event.'"
Cancel = True
End If
End If

What am I doing wrong?
 
D

Dirk Goldgar

Laura C. said:
Hi,

I've seen several useful for suggestions for how to get a field in a form
to
be required based on the value in another field, but none of the code
provided is working for me. I think it may have something to do with the
fact
that the "if" statement involves text -- I've been using the asterisk to
stand in for the rest of the string (i.e., only the first few words need
to
be present to make the other field required). But do I want an "=" sign
here,
or the expression "Is Like"?

I'm also wondering if part of the problem lies with the fact that the
field
that I want to be required under certain conditions is a list box in which
I
have generated the values from within the form (i.e., they are not being
called up from a table somewhere, also the values entered do GO INTO my
table).

Here is the code I've tried inserting under "BeforeUpdate" for the form:

If Me.Action = "Sales/purchases*" Then
If IsNull(Me.Event) = True Then
MsgBox "You must enter 'Purchase' or 'Redeem' under 'Event.'"
Cancel = True
End If
End If

What am I doing wrong?


I think you need to change this line:
If Me.Action = "Sales/purchases*" Then

.... to this:

If Me.Action Like "Sales/purchases*" Then

That may be the only change you need to make, but I can't be sure.
 
L

Laura C.

Hi Dirk,

Tried that, but it's still not working.

One question: do I name the second field "Me.Event" (what it's called in the
table) or "Me.List22" (what it's called in the form)? Could that be the
source of the problem?

Laura C.
 
D

Dirk Goldgar

Laura C. said:
Hi Dirk,

Tried that, but it's still not working.

One question: do I name the second field "Me.Event" (what it's called in
the
table) or "Me.List22" (what it's called in the form)? Could that be the
source of the problem?


Hi, Laura -

I'd have thought that either would work, but try List22 if that's the
control on the form that is bound to the Event field.
 

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