If Then Statement

K

Kim

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
 
P

PC Datasheet

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
[email protected]
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.
 
J

John Marshall, MVP

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
 
K

Ken Snell [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
 
D

Dirk Goldgar

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.
 
P

PC Datasheet

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
 
D

Dirk Goldgar

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.
 
P

PC Datasheet

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
 
J

John Marshall, MVP

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
 
J

John Marshall, 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
 
K

Kim

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
[email protected]
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.
 
Top