If Then Statement

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

Guest

Good Morning! I hope someone can help me with an If Then Statement. I have a
customer record, and from that record I wish to print a report specific to
that customer record. I would like the user to push "Print Report" and based
on what the field "Type" says, I would like 1 of 3 reports to print out. Can
anyone suggest the proper If Then Statement, or any other suggestions? Thanks
so much for any help you can provide!

Kim
 
Use a query that includes CustomerID as the basis of each report. Put the
following expression in the criteria of CustomerID in each query:
Forms!MyForm!CustomerID

Put the following in the Click event of a button on your form:
Select Case Me!Type
Case ValueOfType1
DoCmd.OpenReport "NameOfReport1",acPreview
Case ValueOfType2
DoCmd.OpenReport "NameOfReport2",acPreview
Case ValueOfType3
DoCmd.OpenReport "NameOfReport3",acPreview
End Select

If your form is a single form, you don't need to do anything but click the
button. If it is a continuous form, you need to click on the customer record
first.


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com

If you don't get the help you need in the newsgroup, I can help you for a
very reasonable fee. Over 1000 Access users have come to me for help.
 
PC Datasheet said:
If you don't get the help you need in the newsgroup, I can help you for a
very reasonable fee. Over 1000 Access users have come to me for help.


Still ambulance chasing and insulting all those who do help. If you are so
good, why do you not help the user in the newsgroup rather than promoting
your own business?

John... Visio MVP
 
You can pass the customer identify value to the report directly so that the
report can "generically" be based on a query that has no criterion
expression in it. Assuming that you're using a field named CustID as the
customer identifier:

Private Sub cmdPrintReport_Click()
Const strReport1 As String = "NameOfReport1"
Const strReport2 As String = "NameOfReport2"
Const strReport3 As String = "NameOfReport3"
If Me.[Type].Value = "OneValue" Then
DoCmd.OpenReport strReport1, , , "CustID=" & Me.CustID.Value
ElseIf Me.[Type].Value = "TwoValue" Then
DoCmd.OpenReport strReport2, , , "CustID=" & Me.CustID.Value
If Me.[Type].Value = "ThreeValue" Then
DoCmd.OpenReport strReport3, , , "CustID=" & Me.CustID.Value
End If
End Sub

Or you can use Select Case structure:

Private Sub cmdPrintReport_Click()
Const strReport1 As String = "NameOfReport1"
Const strReport2 As String = "NameOfReport2"
Const strReport3 As String = "NameOfReport3"
Select Case Me.[Type].Value
Case "OneValue"
DoCmd.OpenReport strReport1, , , "CustID=" & Me.CustID.Value
Case "TwoValue"
DoCmd.OpenReport strReport2, , , "CustID=" & Me.CustID.Value
Case "ThreeValue"
DoCmd.OpenReport strReport3, , , "CustID=" & Me.CustID.Value
End Select
End Sub


Alternatively, if "Type" field holds a number (1, 2, or 3):

Private Sub cmdPrintReport_Click()
Dim strReport As String
Const strReport1 As String = "NameOfReport1"
Const strReport2 As String = "NameOfReport2"
Const strReport3 As String = "NameOfReport3"
DoCmd.OpenReport Choose(Me.[Type].Value, strReport1, _
strReport2, strReport3), , , "CustID=" & Me.CustID.Value
End Sub
 
PC Datasheet said:
Use a query that includes CustomerID as the basis of each report. Put the
following expression in the criteria of CustomerID in each query:
Forms!MyForm!CustomerID

Put the following in the Click event of a button on your form:
Select Case Me!Type
Case ValueOfType1
DoCmd.OpenReport "NameOfReport1",acPreview
Case ValueOfType2
DoCmd.OpenReport "NameOfReport2",acPreview
Case ValueOfType3
DoCmd.OpenReport "NameOfReport3",acPreview
End Select

If your form is a single form, you don't need to do anything but click the
button. If it is a continuous form, you need to click on the customer record
first.

These 1000 (if at all a real figure..) is only the result of
-- 4 years abusing the newsgroups.
-- 4 years blatantly advertising and jobhunting.

You just don't care about the newsgroups. You have no ethics at all.
You only care about making money, and you act as if the groups are your private hunting ground.

-- You abuse this group and others for job-hunting and advertising over and over again
-- You are insulting lots of people here when they ask you to stop this
-- You posted as Steve, Ron, Tom, Rachel, Kathy, Kristine, Heather and ??? while asking questions
(the latest 'star's': 'Access Resource' and Tom (e-mail address removed))
-- You try to sell a CD ($125,--) with FREE code you gathered from these groups here
-- There even has been a 'Scam-alert' about you which has been explained recently in the thread 'To all':
http://groups.google.com/group/comp.databases.ms-access/msg/46038ba2954261f9?hl=en
-- Also recently it became clear that you have been spamming innocent people asking questions:
http://groups.google.com/group/comp.databases.ms-access/msg/4f76d0ed3e5f58ad?hl=en

So why would ANYBODY ever trust a person like you and hire you?
********************************************************

To all: Explanation and more on this answer to Steve:
http://home.tiscali.nl/arracom/stopsteve.html

Arno R
 
John Marshall said:
Still ambulance chasing and insulting all those who do help. If you
are so good, why do you not help the user in the newsgroup rather
than promoting your own business?

For what it's worth, John, though I believe that PC Datasheet has posted
inappropriately imany times n the past, I don't see a real problem with
this particular post, and I think you are being unfair. So long as he
gives a real answer to the question -- which he did in this case -- and
doesn't direct the user away from the free support that is available, I
don't have a problem with the line you quoted in his sig.
 
Dirk,

Thanks for the support!

Arno R (not his real name) and John Marshall "think" they are the Don
Quixotes of the newsgroups and "think" what they are doing is for the good
of the newsgroups! Their holier than thou posts are nothing but a waste of
newsreaders' time. They are the ones in violation of the Rules Of Conduct
for the newsgroups.

Steve
 
PC Datasheet said:
Dirk,

Thanks for the support!

Arno R (not his real name) and John Marshall "think" they are the Don
Quixotes of the newsgroups and "think" what they are doing is for the
good of the newsgroups! Their holier than thou posts are nothing but
a waste of newsreaders' time. They are the ones in violation of the
Rules Of Conduct for the newsgroups.

Steve, I don't support many other things you've done, which I do believe
violate the spirit of these newsgroups, even where they have kept
"within the letter of the law." Arno R and John Marshall have good
reason to be incensed. But as I said, I don't find anything wrong with
this post, and I think it's important to be clear on what's okay and
what isn't.
 
Dirk,

I just found this quote that is very appropriate to Arno R (not his real
name) and John Marshall ----

Great spirits will always encounter violent opposition from small minds.

- Albert Einstein

Steve
 
Dirk Goldgar said:
For what it's worth, John, though I believe that PC Datasheet has posted
inappropriately imany times n the past, I don't see a real problem with
this particular post, and I think you are being unfair. So long as he
gives a real answer to the question -- which he did in this case -- and
doesn't direct the user away from the free support that is available, I
don't have a problem with the line you quoted in his sig.

Dirk Goldgar, MS Access MVP
www.datagnostics.com


Thanks Dirk.

The new tag line is slightly better than his "call me" posts, but it is an
insult to the regular contributors because it implies that only he can
provide the answer and there will be a fee attached. The tagline is intended
to direct users from the newsgroups.

The bottom line is that master santos's contributions are only to promote
his business. An activity which is against the spirit of why these
newsgroups were created.


John... Visio MVP
 
PC Datasheet said:
Arno R (not his real name) and John Marshall "think" they are the Don
Quixotes of the newsgroups and "think" what they are doing is for the good
of the newsgroups! Their holier than thou posts are nothing but a waste of
newsreaders' time. They are the ones in violation of the Rules Of Conduct
for the newsgroups.

Steve

Master santos, Arno R is his real name and JM is mine, but PC Datasheet is
not yours. We do not think, we know that these newsgroups were not provided
for commercial use, a point you have chosen to ignore.

So how is pointing out that you have again crossed the line against the
Rules Of Conduct for the newsgroups?

John... Visio MVP
 
The new tag line is slightly better than his "call me" posts, but it is an
insult to the regular contributors because it implies that only he can
provide the answer and there will be a fee attached. The tagline is intended
to direct users from the newsgroups.

Difference is: He was not *always* using "call me" posts. Now he *is* using this sig always ... (sic)

This newborn sig is a clear violation of the spirit of the newsgroups.
Where I live this is called jobhunting. Period.

I will chase each and every of these posts and I hope a lot of people will support me.

Arno R
 
Thanks for the help, that worked perfectly

PC Datasheet said:
Use a query that includes CustomerID as the basis of each report. Put the
following expression in the criteria of CustomerID in each query:
Forms!MyForm!CustomerID

Put the following in the Click event of a button on your form:
Select Case Me!Type
Case ValueOfType1
DoCmd.OpenReport "NameOfReport1",acPreview
Case ValueOfType2
DoCmd.OpenReport "NameOfReport2",acPreview
Case ValueOfType3
DoCmd.OpenReport "NameOfReport3",acPreview
End Select

If your form is a single form, you don't need to do anything but click the
button. If it is a continuous form, you need to click on the customer record
first.


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com

If you don't get the help you need in the newsgroup, I can help you for a
very reasonable fee. Over 1000 Access users have come to me for help.
 
Back
Top