Form verification coding question

A

Al

I would like to put in a verification check in a form, however I can't
seem to figure out how to get it to work.

I have a field entitled "PaymentType" and a field entitled
"CheckNumber".
PaymentType is a drop-down list.
One of the PaymentType options is "Check".
I would like to make it such that if the user selects the PaymentType
of "Check" the form requires the user to input a CheckNumber.

I've played around with IIF statments, but they don't seem to be
working right.

Help? Please?
 
J

Jeff Boyce

One approach would be to add code to the form's BeforeUpdate event that does
the verification. You could use an If() function for this.

Given that you/Access probably wouldn't "know" until after the user
attempted to save the record, this might be your best approach.

Note, however, that you could leave the CheckNumber textbox greyed-out
(Enabled = False), and turn it "on" only if the "Check" option is selected
(and turn it back off if another option is chosen).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
O

OatBoatBaBoatBoatMcBoatNut.Nog

Thanks for the help, Jeff.

I was hoping you'd be able to offer a more detailed description of how
to do this. We've tried functions like
IIf([PaymentType]="Check",[CheckNumber].Visible, null) after setting
the CheckNumber field to disabled, but we're both rather new to Access
and nothing we come up with yields useful results.

Can you offer any more assistance or more detailed instructions?

Thanks,
Katherine
 
O

OatBoatBaBoatBoatMcBoatNut.Nog

Thanks for the help, Jeff.

I was hoping you'd be able to offer a more detailed description of how
to do this. We've tried functions like
IIf([PaymentType]="Check",[CheckNumber].Visible, null) after setting
the CheckNumber field to disabled, but we're both rather new to Access
and nothing we come up with yields useful results.

Can you offer any more assistance or more detailed instructions?

Thanks,
Katherine
 
K

Katherine

Thanks for the help, Jeff.

I was hoping you'd be able to offer a more detailed description of how
to do this. We've tried functions like
IIf([PaymentType]="Check",[CheckNumber].Visible, null) after setting
the CheckNumber field to disabled, but we're both rather new to Access
and nothing we come up with yields useful results.

Can you offer any more assistance or more detailed instructions?

Thanks,
Katherine
 
J

Jeff Boyce

Take a look in Access HELP for specific syntax on commands.

You'll need to understand how to use VBA in form events (the BeforeUpdate
event) to make it work for you.

Your code might look something like (actual syntax may vary):

If Me.PaymentType = "Check" Then
Me.CheckNumber.Enabled = True
Else
Me.CheckNumber.Enabled = False
End If

or a more-abbreviated version:

Me.CheckNumber.Enabled = (Me.PaymentType = "Check")

This assumes that the actual value of the control you call [PaymentType] is
"Check" and not an ID number...

Good luck!

Jeff Boyce
Microsoft Office/Access MVP


Thanks for the help, Jeff.

I was hoping you'd be able to offer a more detailed description of how
to do this. We've tried functions like
IIf([PaymentType]="Check",[CheckNumber].Visible, null) after setting
the CheckNumber field to disabled, but we're both rather new to Access
and nothing we come up with yields useful results.

Can you offer any more assistance or more detailed instructions?

Thanks,
Katherine

Jeff said:
One approach would be to add code to the form's BeforeUpdate event that
does
the verification. You could use an If() function for this.

Given that you/Access probably wouldn't "know" until after the user
attempted to save the record, this might be your best approach.

Note, however, that you could leave the CheckNumber textbox greyed-out
(Enabled = False), and turn it "on" only if the "Check" option is
selected
(and turn it back off if another option is chosen).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Top