Macros vs. Code

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

Guest

When I am in a field property and go to build an event, it asks me if I want
"Expression Builder", "Code Builder", or "Macro Builder". I thought I would
do code builder and this is the code that I built:

Private Sub MethodofPaymentID_AfterUpdate()
If frmPurchaseOrder.MethodofPaymentID = MasterCard Is True Then
DoCmd.OpenForm frmExpenseReport
Else: frmPurchaseOrder.MethodofPaymentID = MasterCard Is False
DoCmd.GoToControl SupplierID
End If
End Sub

I don't know if this code is correct or anything, but when I try and test it
its bring up the macro name screen. Do I have to name it with a macro name
and put the macro name into the after update property? Obviously, I am new
to writing code, etc. but I was pretty proud that I managed to get through
this far without "Mr. Red" showing up. Any help is appreciated. Thanks.
 
When you view the Event tab of the Properties window for the
MethodofPaymentID control, does [Event Procedure] show in the box next to
After Update? If not, then the form does not know that you want to run VBA
code. The code that you wrote should be in the code module that is "behind"
the form, and the [Event Procedure] text should be in that property box.
 
Yes, [Event Procedure] shows on the line "After Update" but nothing happens
when I update the field. Hold on . . . I thought I would double check and
for some reason it is recognizing the code. Sorry, but I think when I copied
the [Event Procedure] and moved it to After Update rather than on Exit, I did
not know that I needed to go into the code and change it there. So, now, it
runs but I get the error message "Compile Error: Type mismatch" on the "is
True" statement. I am not sure how to tell it that if I choose "Mastercard"
in the drop down to open another form but if it is NOT "Mastercard," then
just go to the next field.
--
S


Ken Snell said:
When you view the Event tab of the Properties window for the
MethodofPaymentID control, does [Event Procedure] show in the box next to
After Update? If not, then the form does not know that you want to run VBA
code. The code that you wrote should be in the code module that is "behind"
the form, and the [Event Procedure] text should be in that property box.

--

Ken Snell
<MS ACCESS MVP>

Sharon said:
When I am in a field property and go to build an event, it asks me if I
want
"Expression Builder", "Code Builder", or "Macro Builder". I thought I
would
do code builder and this is the code that I built:

Private Sub MethodofPaymentID_AfterUpdate()
If frmPurchaseOrder.MethodofPaymentID = MasterCard Is True Then
DoCmd.OpenForm frmExpenseReport
Else: frmPurchaseOrder.MethodofPaymentID = MasterCard Is False
DoCmd.GoToControl SupplierID
End If
End Sub

I don't know if this code is correct or anything, but when I try and test
it
its bring up the macro name screen. Do I have to name it with a macro
name
and put the macro name into the after update property? Obviously, I am
new
to writing code, etc. but I was pretty proud that I managed to get through
this far without "Mr. Red" showing up. Any help is appreciated. Thanks.
 
"Is" in this syntax operates on Objects, not Values.

Also, the syntax of the Boolean expression looks incorrect.

What is the Data-Type for MethodofPaymentID?

If it is Text, I think you need:

If (Forms!frmPurchaseOrder.MethodofPaymentID = "MasterCard") Then
...


I am not sure what you tried to do with the statement:

frmPurchaseOrder.MethodofPaymentID = MasterCard Is False
 
Van said:
I am not sure what you tried to do with the statement:

frmPurchaseOrder.MethodofPaymentID = MasterCard Is False

I think it means this:
Me.MethodofPaymentID <> "MasterCard"

But in the end, I think the code required is:
If Me.MethodofPaymentID = "MasterCard" Then
DoCmd.OpenForm frmExpenseReport
Else
DoCmd.GoToControl SupplierID
End If
 
That's what I guessed but the O.P. used "Else" with the colon after so the
statement looks like an assignment statement, not a Boolean expression being
used as criteria (for ElseIf?)
 
Van,

I cheated ;-) I also read right through to the last sentence of her
last post <g>
 
Back
Top