Code: If This Then This - Macros

S

Singinbeauty

Hello,
I have a form of which I enter in certain information and depending on one
field I need to have a certain report open. I had this working at one point
but it got deleted and for the life of me I can't remember what the correct
code should be.

Right now it is:

Private Sub WAF_Click()
If [CREDIT TYPE] = "CM" Then
DoCmd.RunMacro [CRN NOTICE]
Else
DoCmd.RunMacro [AB NOTICE]
End If
End Sub

What I need to happen is when a button is pushed the database will check the
'Credit Type' field for either 'CM' or 'AB'. If it is 'CM' then the macro
[CRN NOTICE] needs to run, if not then [AB NOTICE] should run. Please help!!!!
 
K

Klatuu

What is the question? The code appears to be correct. I would offer some
advice, if [CREDIT TYPE] is a control on your form, qualify it with a
reference to the form"
Me.[CREDIT TYPE]
 
S

Singinbeauty

Well, when I click the button it gives me runtime error '2465':

Microsoft Office Access can't find the field '|' referred to in your
expression

The me.Credit_Type doesn't seem to work either.

Klatuu said:
What is the question? The code appears to be correct. I would offer some
advice, if [CREDIT TYPE] is a control on your form, qualify it with a
reference to the form"
Me.[CREDIT TYPE]
--
Dave Hargis, Microsoft Access MVP


Singinbeauty said:
Hello,
I have a form of which I enter in certain information and depending on one
field I need to have a certain report open. I had this working at one point
but it got deleted and for the life of me I can't remember what the correct
code should be.

Right now it is:

Private Sub WAF_Click()
If [CREDIT TYPE] = "CM" Then
DoCmd.RunMacro [CRN NOTICE]
Else
DoCmd.RunMacro [AB NOTICE]
End If
End Sub

What I need to happen is when a button is pushed the database will check the
'Credit Type' field for either 'CM' or 'AB'. If it is 'CM' then the macro
[CRN NOTICE] needs to run, if not then [AB NOTICE] should run. Please help!!!!
 
K

Klatuu

Is [CREDIT TYPE ] a field in your form's recordset or the name of a control?
What is the name of the control it is bound to. This is ony a syntax problem.
--
Dave Hargis, Microsoft Access MVP


Singinbeauty said:
Well, when I click the button it gives me runtime error '2465':

Microsoft Office Access can't find the field '|' referred to in your
expression

The me.Credit_Type doesn't seem to work either.

Klatuu said:
What is the question? The code appears to be correct. I would offer some
advice, if [CREDIT TYPE] is a control on your form, qualify it with a
reference to the form"
Me.[CREDIT TYPE]
--
Dave Hargis, Microsoft Access MVP


Singinbeauty said:
Hello,
I have a form of which I enter in certain information and depending on one
field I need to have a certain report open. I had this working at one point
but it got deleted and for the life of me I can't remember what the correct
code should be.

Right now it is:

Private Sub WAF_Click()
If [CREDIT TYPE] = "CM" Then
DoCmd.RunMacro [CRN NOTICE]
Else
DoCmd.RunMacro [AB NOTICE]
End If
End Sub

What I need to happen is when a button is pushed the database will check the
'Credit Type' field for either 'CM' or 'AB'. If it is 'CM' then the macro
[CRN NOTICE] needs to run, if not then [AB NOTICE] should run. Please help!!!!
 
F

fcmedina78

You should be able to copy and paste the following code and it should work.

Private Sub WAF_Click()

Const CreditType = "CM"
' Me! Lets access know that you are addressing a field in the current form
' Not sure if you will need the quotes arround CM when defining the constant

If Me!Credit Type.Value = CreditType Then
DoCmd.RunMacro "CRN Notice"
Else
DoCmd.RunMacro "AB Notice"
End If
End Sub
 
S

Singinbeauty

It is the name of a field and the Control Source... Is it case sensitive?
Because the Name is Credit Type and the Control Source is CREDIT TYPE.

Thank you so much for your help on this... it is driving me batty!!!!

Klatuu said:
Is [CREDIT TYPE ] a field in your form's recordset or the name of a control?
What is the name of the control it is bound to. This is ony a syntax problem.
--
Dave Hargis, Microsoft Access MVP


Singinbeauty said:
Well, when I click the button it gives me runtime error '2465':

Microsoft Office Access can't find the field '|' referred to in your
expression

The me.Credit_Type doesn't seem to work either.

Klatuu said:
What is the question? The code appears to be correct. I would offer some
advice, if [CREDIT TYPE] is a control on your form, qualify it with a
reference to the form"
Me.[CREDIT TYPE]
--
Dave Hargis, Microsoft Access MVP


:

Hello,
I have a form of which I enter in certain information and depending on one
field I need to have a certain report open. I had this working at one point
but it got deleted and for the life of me I can't remember what the correct
code should be.

Right now it is:

Private Sub WAF_Click()
If [CREDIT TYPE] = "CM" Then
DoCmd.RunMacro [CRN NOTICE]
Else
DoCmd.RunMacro [AB NOTICE]
End If
End Sub

What I need to happen is when a button is pushed the database will check the
'Credit Type' field for either 'CM' or 'AB'. If it is 'CM' then the macro
[CRN NOTICE] needs to run, if not then [AB NOTICE] should run. Please help!!!!
 
S

Singinbeauty

That worked!!! Thank you so much!

fcmedina78 said:
You should be able to copy and paste the following code and it should work.

Private Sub WAF_Click()

Const CreditType = "CM"
' Me! Lets access know that you are addressing a field in the current form
' Not sure if you will need the quotes arround CM when defining the constant

If Me!Credit Type.Value = CreditType Then
DoCmd.RunMacro "CRN Notice"
Else
DoCmd.RunMacro "AB Notice"
End If
End Sub

Singinbeauty said:
Hello,
I have a form of which I enter in certain information and depending on one
field I need to have a certain report open. I had this working at one point
but it got deleted and for the life of me I can't remember what the correct
code should be.

Right now it is:

Private Sub WAF_Click()
If [CREDIT TYPE] = "CM" Then
DoCmd.RunMacro [CRN NOTICE]
Else
DoCmd.RunMacro [AB NOTICE]
End If
End Sub

What I need to happen is when a button is pushed the database will check the
'Credit Type' field for either 'CM' or 'AB'. If it is 'CM' then the macro
[CRN NOTICE] needs to run, if not then [AB NOTICE] should run. Please help!!!!
 

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