Make Command Button print Specific Report

How do I call up a specific report based on a field on a Form?
I have 5 reports, each designed somewhat similar, but paragraphs are 
different on each.  I would like the form field "Contracttype" determine 
which 
report opens to print or preview. I have tried this.  In the design view I 
created a command button, in the properties under On Click I opened the ... 
button and entered this code under Code Builder.
If ContractType = “Electric” Then DoCmd.OpenReport "Electric"
If ContractType = “Gas” Then DoCmd.OpenReport "Gas"
If ContractType = “Oil” Then DoCmd.OpenReport "Oil"
If ContractType = “HeatPump” Then DoCmd.OpenReport "HeatPump"
If ContractType = “Cooling” Then DoCmd.OpenReport "Cooling"
Exit and Saved but the command button doesn't take me where I want to go.
Can someone tell me if my coding is wrong.  This is Access2000.
Thanks Frank

0
Utf
11/2/2007 9:13:22 PM
access.reports 4434 articles. 0 followers. Follow

6 Replies
1126 Views

Similar Articles

[PageSpeed] 23

What is the complete code. If you copied and pasted the code into this 
message, why are the types of double-quotes different?

I would write code like:
Dim strReportName as String
Select Case Me.ContractType
    Case  "Electric"
        strReportName = "Electric"
    Case  "Gas"
        strReportName = "Gas"
     Case "Oil"
         strReportName = "Oil"
     Case "HeatPump"
         strReportName = "HeatPump"
     Case "Cooling"
         strReportName = "Cooling"
End Case
DoCmd.OpenReport strReportName

Since the report names seem to match the ContractType, you could use:
    DoCmd.OpenReport Me.ContractType
However, I use a naming convention where this would not be as simple.

-- 
Duane Hookom
Microsoft Access MVP


"Francis Cunningham, Jr." wrote:

> How do I call up a specific report based on a field on a Form?
> I have 5 reports, each designed somewhat similar, but paragraphs are 
> different on each.  I would like the form field "Contracttype" determine 
> which 
> report opens to print or preview. I have tried this.  In the design view I 
> created a command button, in the properties under On Click I opened the ... 
> button and entered this code under Code Builder.
> If ContractType = “Electric” Then DoCmd.OpenReport "Electric"
> If ContractType = “Gas” Then DoCmd.OpenReport "Gas"
> If ContractType = “Oil” Then DoCmd.OpenReport "Oil"
> If ContractType = “HeatPump” Then DoCmd.OpenReport "HeatPump"
> If ContractType = “Cooling” Then DoCmd.OpenReport "Cooling"
> Exit and Saved but the command button doesn't take me where I want to go.
> Can someone tell me if my coding is wrong.  This is Access2000.
> Thanks Frank
> 
0
Utf
11/3/2007 3:09:00 AM
After I inserted the code went back to the form with the button and click the 
command button. The visual basic window opened with a pop up stating ‘Compile 
Error   Syntax error’.  The first and last lines was entered – Private Sub 
and  End Sub.  I don’t know how to fix this.

Private Sub Command51_Click()       (This line was Highlighted in yellow 
with an -> in front of Private)
Dim strReportName As String
Select Case Me.ContractType
Case "Electric"
strReportName = "Electric"
Case "Gas"
strReportName = "Gas"
Case "Oil"
strReportName = "Oil"
Case "HeatPump"
strReportName = "HeatPump"
Case "Cooling"
strReportName = "Cooling"
End Case                                (This line was also highlighted)
DoCmd.OpenReport strReportName

End Sub


"Duane Hookom" wrote:

> What is the complete code. If you copied and pasted the code into this 
> message, why are the types of double-quotes different?
> 
> I would write code like:
> Dim strReportName as String
> Select Case Me.ContractType
>     Case  "Electric"
>         strReportName = "Electric"
>     Case  "Gas"
>         strReportName = "Gas"
>      Case "Oil"
>          strReportName = "Oil"
>      Case "HeatPump"
>          strReportName = "HeatPump"
>      Case "Cooling"
>          strReportName = "Cooling"
> End Case
> DoCmd.OpenReport strReportName
> 
> Since the report names seem to match the ContractType, you could use:
>     DoCmd.OpenReport Me.ContractType
> However, I use a naming convention where this would not be as simple.
> 
> -- 
> Duane Hookom
> Microsoft Access MVP
> 
> 
> "Francis Cunningham, Jr." wrote:
> 
> > How do I call up a specific report based on a field on a Form?
> > I have 5 reports, each designed somewhat similar, but paragraphs are 
> > different on each.  I would like the form field "Contracttype" determine 
> > which 
> > report opens to print or preview. I have tried this.  In the design view I 
> > created a command button, in the properties under On Click I opened the ... 
> > button and entered this code under Code Builder.
> > If ContractType = “Electric” Then DoCmd.OpenReport "Electric"
> > If ContractType = “Gas” Then DoCmd.OpenReport "Gas"
> > If ContractType = “Oil” Then DoCmd.OpenReport "Oil"
> > If ContractType = “HeatPump” Then DoCmd.OpenReport "HeatPump"
> > If ContractType = “Cooling” Then DoCmd.OpenReport "Cooling"
> > Exit and Saved but the command button doesn't take me where I want to go.
> > Can someone tell me if my coding is wrong.  This is Access2000.
> > Thanks Frank
> > 
0
Utf
11/3/2007 2:41:02 PM
On Sat, 3 Nov 2007 07:41:02 -0700, Francis Cunningham, Jr. wrote:

> After I inserted the code went back to the form with the button and click the 
> command button. The visual basic window opened with a pop up stating ��Compile 
> Error   Syntax error��.  The first and last lines was entered �V Private Sub 
> and  End Sub.  I don��t know how to fix this.
> 
> Private Sub Command51_Click()       (This line was Highlighted in yellow 
> with an -> in front of Private)
> Dim strReportName As String
> Select Case Me.ContractType
> Case "Electric"
> strReportName = "Electric"
> Case "Gas"
> strReportName = "Gas"
> Case "Oil"
> strReportName = "Oil"
> Case "HeatPump"
> strReportName = "HeatPump"
> Case "Cooling"
> strReportName = "Cooling"
> End Case                                (This line was also highlighted)
> DoCmd.OpenReport strReportName
> 
> End Sub
> 
> "Duane Hookom" wrote:
> 
>> What is the complete code. If you copied and pasted the code into this 
>> message, why are the types of double-quotes different?
>> 
>> I would write code like:
>> Dim strReportName as String
>> Select Case Me.ContractType
>>     Case  "Electric"
>>         strReportName = "Electric"
>>     Case  "Gas"
>>         strReportName = "Gas"
>>      Case "Oil"
>>          strReportName = "Oil"
>>      Case "HeatPump"
>>          strReportName = "HeatPump"
>>      Case "Cooling"
>>          strReportName = "Cooling"
>> End Case
>> DoCmd.OpenReport strReportName
>> 
>> Since the report names seem to match the ContractType, you could use:
>>     DoCmd.OpenReport Me.ContractType
>> However, I use a naming convention where this would not be as simple.
>> 
>> -- 
>> Duane Hookom
>> Microsoft Access MVP
>> 
>> "Francis Cunningham, Jr." wrote:
>> 
>>> How do I call up a specific report based on a field on a Form?
>>> I have 5 reports, each designed somewhat similar, but paragraphs are 
>>> different on each.  I would like the form field "Contracttype" determine 
>>> which 
>>> report opens to print or preview. I have tried this.  In the design view I 
>>> created a command button, in the properties under On Click I opened the ... 
>>> button and entered this code under Code Builder.
>>> If ContractType = ��Electric�� Then DoCmd.OpenReport "Electric"
>>> If ContractType = ��Gas�� Then DoCmd.OpenReport "Gas"
>>> If ContractType = ��Oil�� Then DoCmd.OpenReport "Oil"
>>> If ContractType = ��HeatPump�� Then DoCmd.OpenReport "HeatPump"
>>> If ContractType = ��Cooling�� Then DoCmd.OpenReport "Cooling"
>>> Exit and Saved but the command button doesn't take me where I want to go.
>>> Can someone tell me if my coding is wrong.  This is Access2000.
>>> Thanks Frank
>>>

Just some thoughts ....

1)  Did you Compile your code before attempting to run it?

I don't believe this is a complete Copy and Paste of the actual code.

The VB editor will choke on
End Case

It should be
End Select

t's also possible you didn't completely delete all of your previous
code.

2)  When asking a question about code, it's always best to copy and
paste the actual code. Sometimes it is just an inappropriate dot or
perhaps a  miss-spelled word causing the problem. Spell it wrong in
your code but spell it right here and no-one will ever be able to
resolve your problem.
Since the rest of this code looks OK, it is probably not identical to
the actual VBA code.

3)  After changing End Case to End Select, comile the code. 
Debug + Compile. 
If you still have a problem, copy and paste your code intg  another
reply.

4)  But then I don't understand why you are jumping through hoops
trying to do all of this.
In each instance of your Select Case code, if the  Case = Something
the strReportName = The same something. 
Why not just go directly to:

DoCmd.OpenReport Me.[ContactType]

No need of If ...  then, Select Case, or any other VBA.

5)  Frankly, if it were me, I would have one report containing all of
the 5 different paragraphs, and make each paragraph Visible or Not
Visible according to the [ContactType] value, i.e.
Me![ParagraphElectric].Visible = Me![ContactType] = "Electric" 
Me![ParagraphGas].Visible = Me![ContactType] = "Gas" 
etc.
It would make report upkeep simpler. Only one report to maintain, not
five.

6)  All of the above assumes the actual stored value of [ContactType]
is Text.  
If [ContactType] is actually a Combo Box (or a LookUp field) , what is
stored may not neccesarily be what is displayed.
-- 
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
0
fredg
11/3/2007 6:22:17 PM
Now when I enter the code and compile it, go back to the specific form click 
on the command button Labeled 51, I get the error message 'Object does not 
support this property'. The VB window open and the highlighted line is 
'Select Case Me.ContractType'
Again, what I am trying to do is create a command button that will print a 
report based on the ContractType. If 'ContractType' is Electric then the 
printed report should be the report named 'Electric'.
This is the complete code for the command button:
Private Sub Command51_Click()
Dim strReportName As String
Select Case Me.ContractType
Case "Electric"
strReportName = "Electric"
Case "Gas"
strReportName = "Gas"
Case "Oil"
strReportName = "Oil"
Case "HeatPump"
strReportName = "HeatPump"
Case "Cooling"
strReportName = "Cooling"
End Select
DoCmd.OpenReport strReportName

End Sub

I appreciates everyone input on this.
Frank
"fredg" wrote:

> On Sat, 3 Nov 2007 07:41:02 -0700, Francis Cunningham, Jr. wrote:
> 
> > After I inserted the code went back to the form with the button and click the 
> > command button. The visual basic window opened with a pop up stating ‘Compile 
> > Error   Syntax error’.  The first and last lines was entered – Private Sub 
> > and  End Sub.  I don’t know how to fix this.
> > 
> > Private Sub Command51_Click()       (This line was Highlighted in yellow 
> > with an -> in front of Private)
> > Dim strReportName As String
> > Select Case Me.ContractType
> > Case "Electric"
> > strReportName = "Electric"
> > Case "Gas"
> > strReportName = "Gas"
> > Case "Oil"
> > strReportName = "Oil"
> > Case "HeatPump"
> > strReportName = "HeatPump"
> > Case "Cooling"
> > strReportName = "Cooling"
> > End Case                                (This line was also highlighted)
> > DoCmd.OpenReport strReportName
> > 
> > End Sub
> > 
> > "Duane Hookom" wrote:
> > 
> >> What is the complete code. If you copied and pasted the code into this 
> >> message, why are the types of double-quotes different?
> >> 
> >> I would write code like:
> >> Dim strReportName as String
> >> Select Case Me.ContractType
> >>     Case  "Electric"
> >>         strReportName = "Electric"
> >>     Case  "Gas"
> >>         strReportName = "Gas"
> >>      Case "Oil"
> >>          strReportName = "Oil"
> >>      Case "HeatPump"
> >>          strReportName = "HeatPump"
> >>      Case "Cooling"
> >>          strReportName = "Cooling"
> >> End Case
> >> DoCmd.OpenReport strReportName
> >> 
> >> Since the report names seem to match the ContractType, you could use:
> >>     DoCmd.OpenReport Me.ContractType
> >> However, I use a naming convention where this would not be as simple.
> >> 
> >> -- 
> >> Duane Hookom
> >> Microsoft Access MVP
> >> 
> >> "Francis Cunningham, Jr." wrote:
> >> 
> >>> How do I call up a specific report based on a field on a Form?
> >>> I have 5 reports, each designed somewhat similar, but paragraphs are 
> >>> different on each.  I would like the form field "Contracttype" determine 
> >>> which 
> >>> report opens to print or preview. I have tried this.  In the design view I 
> >>> created a command button, in the properties under On Click I opened the ... 
> >>> button and entered this code under Code Builder.
> >>> If ContractType = “Electric” Then DoCmd.OpenReport "Electric"
> >>> If ContractType = “Gas” Then DoCmd.OpenReport "Gas"
> >>> If ContractType = “Oil” Then DoCmd.OpenReport "Oil"
> >>> If ContractType = “HeatPump” Then DoCmd.OpenReport "HeatPump"
> >>> If ContractType = “Cooling” Then DoCmd.OpenReport "Cooling"
> >>> Exit and Saved but the command button doesn't take me where I want to go.
> >>> Can someone tell me if my coding is wrong.  This is Access2000.
> >>> Thanks Frank
> >>>
> 
> Just some thoughts ....
> 
> 1)  Did you Compile your code before attempting to run it?
> 
> I don't believe this is a complete Copy and Paste of the actual code.
> 
> The VB editor will choke on
> End Case
> 
> It should be
> End Select
> 
> t's also possible you didn't completely delete all of your previous
> code.
> 
> 2)  When asking a question about code, it's always best to copy and
> paste the actual code. Sometimes it is just an inappropriate dot or
> perhaps a  miss-spelled word causing the problem. Spell it wrong in
> your code but spell it right here and no-one will ever be able to
> resolve your problem.
> Since the rest of this code looks OK, it is probably not identical to
> the actual VBA code.
> 
> 3)  After changing End Case to End Select, comile the code. 
> Debug + Compile. 
> If you still have a problem, copy and paste your code intg  another
> reply.
> 
> 4)  But then I don't understand why you are jumping through hoops
> trying to do all of this.
> In each instance of your Select Case code, if the  Case = Something
> the strReportName = The same something. 
> Why not just go directly to:
> 
> DoCmd.OpenReport Me.[ContactType]
> 
> No need of If ...  then, Select Case, or any other VBA.
> 
> 5)  Frankly, if it were me, I would have one report containing all of
> the 5 different paragraphs, and make each paragraph Visible or Not
> Visible according to the [ContactType] value, i.e.
> Me![ParagraphElectric].Visible = Me![ContactType] = "Electric" 
> Me![ParagraphGas].Visible = Me![ContactType] = "Gas" 
> etc.
> It would make report upkeep simpler. Only one report to maintain, not
> five.
> 
> 6)  All of the above assumes the actual stored value of [ContactType]
> is Text.  
> If [ContactType] is actually a Combo Box (or a LookUp field) , what is
> stored may not neccesarily be what is displayed.
> -- 
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
> 
0
Utf
11/4/2007 1:52:00 PM
On Sun, 4 Nov 2007 05:52:00 -0800, Francis Cunningham, Jr. wrote:

> Now when I enter the code and compile it, go back to the specific form click 
> on the command button Labeled 51, I get the error message 'Object does not 
> support this property'. The VB window open and the highlighted line is 
> 'Select Case Me.ContractType'
> Again, what I am trying to do is create a command button that will print a 
> report based on the ContractType. If 'ContractType' is Electric then the 
> printed report should be the report named 'Electric'.
> This is the complete code for the command button:
> Private Sub Command51_Click()
> Dim strReportName As String
> Select Case Me.ContractType
> Case "Electric"
> strReportName = "Electric"
> Case "Gas"
> strReportName = "Gas"
> Case "Oil"
> strReportName = "Oil"
> Case "HeatPump"
> strReportName = "HeatPump"
> Case "Cooling"
> strReportName = "Cooling"
> End Select
> DoCmd.OpenReport strReportName
> 
> End Sub
> 
> I appreciates everyone input on this.
> Frank
> "fredg" wrote:
> 
>> On Sat, 3 Nov 2007 07:41:02 -0700, Francis Cunningham, Jr. wrote:
>> 
>>> After I inserted the code went back to the form with the button and click the 
>>> command button. The visual basic window opened with a pop up stating ��Compile 
>>> Error   Syntax error��.  The first and last lines was entered �V Private Sub 
>>> and  End Sub.  I don��t know how to fix this.
>>> 
>>> Private Sub Command51_Click()       (This line was Highlighted in yellow 
>>> with an -> in front of Private)
>>> Dim strReportName As String
>>> Select Case Me.ContractType
>>> Case "Electric"
>>> strReportName = "Electric"
>>> Case "Gas"
>>> strReportName = "Gas"
>>> Case "Oil"
>>> strReportName = "Oil"
>>> Case "HeatPump"
>>> strReportName = "HeatPump"
>>> Case "Cooling"
>>> strReportName = "Cooling"
>>> End Case                                (This line was also highlighted)
>>> DoCmd.OpenReport strReportName
>>> 
>>> End Sub
>>> 
>>> "Duane Hookom" wrote:
>>> 
>>>> What is the complete code. If you copied and pasted the code into this 
>>>> message, why are the types of double-quotes different?
>>>> 
>>>> I would write code like:
>>>> Dim strReportName as String
>>>> Select Case Me.ContractType
>>>>     Case  "Electric"
>>>>         strReportName = "Electric"
>>>>     Case  "Gas"
>>>>         strReportName = "Gas"
>>>>      Case "Oil"
>>>>          strReportName = "Oil"
>>>>      Case "HeatPump"
>>>>          strReportName = "HeatPump"
>>>>      Case "Cooling"
>>>>          strReportName = "Cooling"
>>>> End Case
>>>> DoCmd.OpenReport strReportName
>>>> 
>>>> Since the report names seem to match the ContractType, you could use:
>>>>     DoCmd.OpenReport Me.ContractType
>>>> However, I use a naming convention where this would not be as simple.
>>>> 
>>>> -- 
>>>> Duane Hookom
>>>> Microsoft Access MVP
>>>> 
>>>> "Francis Cunningham, Jr." wrote:
>>>> 
>>>>> How do I call up a specific report based on a field on a Form?
>>>>> I have 5 reports, each designed somewhat similar, but paragraphs are 
>>>>> different on each.  I would like the form field "Contracttype" determine 
>>>>> which 
>>>>> report opens to print or preview. I have tried this.  In the design view I 
>>>>> created a command button, in the properties under On Click I opened the ... 
>>>>> button and entered this code under Code Builder.
>>>>> If ContractType = ��Electric�� Then DoCmd.OpenReport "Electric"
>>>>> If ContractType = ��Gas�� Then DoCmd.OpenReport "Gas"
>>>>> If ContractType = ��Oil�� Then DoCmd.OpenReport "Oil"
>>>>> If ContractType = ��HeatPump�� Then DoCmd.OpenReport "HeatPump"
>>>>> If ContractType = ��Cooling�� Then DoCmd.OpenReport "Cooling"
>>>>> Exit and Saved but the command button doesn't take me where I want to go.
>>>>> Can someone tell me if my coding is wrong.  This is Access2000.
>>>>> Thanks Frank
>>>>>
>> 
>> Just some thoughts ....
>> 
>> 1)  Did you Compile your code before attempting to run it?
>> 
>> I don't believe this is a complete Copy and Paste of the actual code.
>> 
>> The VB editor will choke on
>> End Case
>> 
>> It should be
>> End Select
>> 
>> t's also possible you didn't completely delete all of your previous
>> code.
>> 
>> 2)  When asking a question about code, it's always best to copy and
>> paste the actual code. Sometimes it is just an inappropriate dot or
>> perhaps a  miss-spelled word causing the problem. Spell it wrong in
>> your code but spell it right here and no-one will ever be able to
>> resolve your problem.
>> Since the rest of this code looks OK, it is probably not identical to
>> the actual VBA code.
>> 
>> 3)  After changing End Case to End Select, comile the code. 
>> Debug + Compile. 
>> If you still have a problem, copy and paste your code intg  another
>> reply.
>> 
>> 4)  But then I don't understand why you are jumping through hoops
>> trying to do all of this.
>> In each instance of your Select Case code, if the  Case = Something
>> the strReportName = The same something. 
>> Why not just go directly to:
>> 
>> DoCmd.OpenReport Me.[ContactType]
>> 
>> No need of If ...  then, Select Case, or any other VBA.
>> 
>> 5)  Frankly, if it were me, I would have one report containing all of
>> the 5 different paragraphs, and make each paragraph Visible or Not
>> Visible according to the [ContactType] value, i.e.
>> Me![ParagraphElectric].Visible = Me![ContactType] = "Electric" 
>> Me![ParagraphGas].Visible = Me![ContactType] = "Gas" 
>> etc.
>> It would make report upkeep simpler. Only one report to maintain, not
>> five.
>> 
>> 6)  All of the above assumes the actual stored value of [ContactType]
>> is Text.  
>> If [ContactType] is actually a Combo Box (or a LookUp field) , what is
>> stored may not neccesarily be what is displayed.
>> -- 
>> Fred
>> Please respond only to this newsgroup.
>> I do not reply to personal e-mail
>>

I have no idea what your error message refers to here.

Why are you continuing along this path, anyway?

Private Sub Command51_Click()
If Not IsNull(Me![ContractType]) Then
      DoCmd.OpenReport Me.[ContactType]
End  if
End Sub
 
is all you need, assuming, once again, that the actual value stored in
[ContractType] is text (see my #4 and #6 in my previous reply).


-- 
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
0
fredg
11/4/2007 5:10:14 PM
Using the Code below, I am still receiving error messages.  What I am trying 
to accomplish is when a button on a particular form is pushed then a 
particular report will open based on a particular field on that form. So if 
the ContractType on the form (which is a text field) is ‘Gas’ then the report 
to open would be ‘Gas’; if the ContractType is ‘Electric’ then the report to 
open would be ‘Electric’ and so on. I though by having the ContractType name 
and the Report name the same it would be less complicated.
One Command button for multiple reports based on ‘ContractType’.

Private Sub Command74_Click()
If Not IsNull(Me![ContractType]) Then
DoCmd.OpenReport Me.[ContactType]
End If
End Sub

I do appreciate all the help on this. I not sure I understand coding all 
that much.
Frank


Private Sub Command74_Click()
If Not IsNull(Me![ContractType]) Then
DoCmd.OpenReport Me.[ContactType]
End If
End Sub

"fredg" wrote:

> On Sun, 4 Nov 2007 05:52:00 -0800, Francis Cunningham, Jr. wrote:
> 
> > Now when I enter the code and compile it, go back to the specific form click 
> > on the command button Labeled 51, I get the error message 'Object does not 
> > support this property'. The VB window open and the highlighted line is 
> > 'Select Case Me.ContractType'
> > Again, what I am trying to do is create a command button that will print a 
> > report based on the ContractType. If 'ContractType' is Electric then the 
> > printed report should be the report named 'Electric'.
> > This is the complete code for the command button:
> > Private Sub Command51_Click()
> > Dim strReportName As String
> > Select Case Me.ContractType
> > Case "Electric"
> > strReportName = "Electric"
> > Case "Gas"
> > strReportName = "Gas"
> > Case "Oil"
> > strReportName = "Oil"
> > Case "HeatPump"
> > strReportName = "HeatPump"
> > Case "Cooling"
> > strReportName = "Cooling"
> > End Select
> > DoCmd.OpenReport strReportName
> > 
> > End Sub
> > 
> > I appreciates everyone input on this.
> > Frank
> > "fredg" wrote:
> > 
> >> On Sat, 3 Nov 2007 07:41:02 -0700, Francis Cunningham, Jr. wrote:
> >> 
> >>> After I inserted the code went back to the form with the button and click the 
> >>> command button. The visual basic window opened with a pop up stating ‘Compile 
> >>> Error   Syntax error’.  The first and last lines was entered – Private Sub 
> >>> and  End Sub.  I don’t know how to fix this.
> >>> 
> >>> Private Sub Command51_Click()       (This line was Highlighted in yellow 
> >>> with an -> in front of Private)
> >>> Dim strReportName As String
> >>> Select Case Me.ContractType
> >>> Case "Electric"
> >>> strReportName = "Electric"
> >>> Case "Gas"
> >>> strReportName = "Gas"
> >>> Case "Oil"
> >>> strReportName = "Oil"
> >>> Case "HeatPump"
> >>> strReportName = "HeatPump"
> >>> Case "Cooling"
> >>> strReportName = "Cooling"
> >>> End Case                                (This line was also highlighted)
> >>> DoCmd.OpenReport strReportName
> >>> 
> >>> End Sub
> >>> 
> >>> "Duane Hookom" wrote:
> >>> 
> >>>> What is the complete code. If you copied and pasted the code into this 
> >>>> message, why are the types of double-quotes different?
> >>>> 
> >>>> I would write code like:
> >>>> Dim strReportName as String
> >>>> Select Case Me.ContractType
> >>>>     Case  "Electric"
> >>>>         strReportName = "Electric"
> >>>>     Case  "Gas"
> >>>>         strReportName = "Gas"
> >>>>      Case "Oil"
> >>>>          strReportName = "Oil"
> >>>>      Case "HeatPump"
> >>>>          strReportName = "HeatPump"
> >>>>      Case "Cooling"
> >>>>          strReportName = "Cooling"
> >>>> End Case
> >>>> DoCmd.OpenReport strReportName
> >>>> 
> >>>> Since the report names seem to match the ContractType, you could use:
> >>>>     DoCmd.OpenReport Me.ContractType
> >>>> However, I use a naming convention where this would not be as simple.
> >>>> 
> >>>> -- 
> >>>> Duane Hookom
> >>>> Microsoft Access MVP
> >>>> 
> >>>> "Francis Cunningham, Jr." wrote:
> >>>> 
> >>>>> How do I call up a specific report based on a field on a Form?
> >>>>> I have 5 reports, each designed somewhat similar, but paragraphs are 
> >>>>> different on each.  I would like the form field "Contracttype" determine 
> >>>>> which 
> >>>>> report opens to print or preview. I have tried this.  In the design view I 
> >>>>> created a command button, in the properties under On Click I opened the ... 
> >>>>> button and entered this code under Code Builder.
> >>>>> If ContractType = “Electric” Then DoCmd.OpenReport "Electric"
> >>>>> If ContractType = “Gas” Then DoCmd.OpenReport "Gas"
> >>>>> If ContractType = “Oil” Then DoCmd.OpenReport "Oil"
> >>>>> If ContractType = “HeatPump” Then DoCmd.OpenReport "HeatPump"
> >>>>> If ContractType = “Cooling” Then DoCmd.OpenReport "Cooling"
> >>>>> Exit and Saved but the command button doesn't take me where I want to go.
> >>>>> Can someone tell me if my coding is wrong.  This is Access2000.
> >>>>> Thanks Frank
> >>>>>
> >> 
> >> Just some thoughts ....
> >> 
> >> 1)  Did you Compile your code before attempting to run it?
> >> 
> >> I don't believe this is a complete Copy and Paste of the actual code.
> >> 
> >> The VB editor will choke on
> >> End Case
> >> 
> >> It should be
> >> End Select
> >> 
> >> t's also possible you didn't completely delete all of your previous
> >> code.
> >> 
> >> 2)  When asking a question about code, it's always best to copy and
> >> paste the actual code. Sometimes it is just an inappropriate dot or
> >> perhaps a  miss-spelled word causing the problem. Spell it wrong in
> >> your code but spell it right here and no-one will ever be able to
> >> resolve your problem.
> >> Since the rest of this code looks OK, it is probably not identical to
> >> the actual VBA code.
> >> 
> >> 3)  After changing End Case to End Select, comile the code. 
> >> Debug + Compile. 
> >> If you still have a problem, copy and paste your code intg  another
> >> reply.
> >> 
> >> 4)  But then I don't understand why you are jumping through hoops
> >> trying to do all of this.
> >> In each instance of your Select Case code, if the  Case = Something
> >> the strReportName = The same something. 
> >> Why not just go directly to:
> >> 
> >> DoCmd.OpenReport Me.[ContactType]
> >> 
> >> No need of If ...  then, Select Case, or any other VBA.
> >> 
> >> 5)  Frankly, if it were me, I would have one report containing all of
> >> the 5 different paragraphs, and make each paragraph Visible or Not
> >> Visible according to the [ContactType] value, i.e.
> >> Me![ParagraphElectric].Visible = Me![ContactType] = "Electric" 
> >> Me![ParagraphGas].Visible = Me![ContactType] = "Gas" 
> >> etc.
> >> It would make report upkeep simpler. Only one report to maintain, not
> >> five.
> >> 
> >> 6)  All of the above assumes the actual stored value of [ContactType]
> >> is Text.  
> >> If [ContactType] is actually a Combo Box (or a LookUp field) , what is
> >> stored may not neccesarily be what is displayed.
> >> -- 
> >> Fred
> >> Please respond only to this newsgroup.
> >> I do not reply to personal e-mail
> >>
> 
> I have no idea what your error message refers to here.
> 
> Why are you continuing along this path, anyway?
> 
> Private Sub Command51_Click()
> If Not IsNull(Me![ContractType]) Then
>       DoCmd.OpenReport Me.[ContactType]
> End  if
> End Sub
>  
> is all you need, assuming, once again, that the actual value stored in
> [ContractType] is text (see my #4 and #6 in my previous reply).
> 
> 
> -- 
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
> 
0
Utf
11/5/2007 5:56:01 PM
Reply:

Similar Artilces:

Can I copy radio buttons so that the second set is independent of.
I have a group of four radio buttons that all point to one cell. My goal is to create a second set that looks identical to the first but which points to a second cell. This is for a questionaire that will have many questions with the same four answer values. I want to be able to quickly create 100 button groups that will each update a separate cell for scoring of the questionaire. There are optionbuttons on the Control toolbox toolbar and there are optionbuttons on the Forms toolbar. Each has different behaviors. If I had to use lots, I'd use the Forms version. Here's a pos...

Reporting IRA distributions
I have an IRA account with corresponding cash account. I am trying to get the distribution from the IRA to show up as "Retirement Income" in the Tax-Related Transactions report. How to do it? The distributions are handled as a transfer from the IRA Investment cash acct to a checking account. Thanks for any help. Money 99, BTW. Do I need to upgrade to a later version? ...

How to make Run Integration work in GP 10
Can anyone tell me how to make the Run Integration tool work in GP 10. We just did our first client upgrade to GP 10 and the client has only 1 integration that they used to be able to run via the RUN INTEGRATION Tool. Any help would be greatly appreciated. -- Tammy Chavez I have the same probelm...did you get any answers to this? I have to go into Integration Manager to run it b/c Tools>Run Integration does nothing. I even checked the ini files to make sure the path is correct. "Tammy Chavez" wrote: > Can anyone tell me how to make the Run Integration tool work in...

Printing In Color
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) I am trying to print a document in word that is color but it is only coming out in black and white. How can I change the color settings on my printer? Word has no setting to print in color v. B/W -- that's a function of your printer & its driver software. The settings are available in the Print dialog in the Copies & Pages List, but exactly where the setting is located depends to a great extent on what printer you have. Some printers also have physical controls on the printer, itself, but that isn't common. ...

making filtering rules?
hi, i am trying to create a rule that goes something like if (site1.com OR site2.org OR site3.gov) AND (agri OR agriculture OR agribusiness) then move to folder X that is, if it is from any of those sites AND has any of those keywords then move it. The problem is i can't seem to figure out the specifying the AND part. Any help/ideas would be greatly appreciated! Cheers -Gaiko ...

Problem with macro assigned to custom toolbar button
Problem with macro assigned to custom toolbar button I am having a probelm with macros assigned to a custom button on custom button. I am using excel 2000. 1. I have created a macro called "Jump" in a workbook named "Test1" 2. I then created a custom toolbar and added a custom toolbar button t that toolbar. 3. Through the customize dialog box I assign the Macro "Jump" to th custom button. Everything works fine UNTIL. If I do a SAVE AS for the workbook "Test1" and call it something els like "Test2" and then close "Test2" an...

set print area #2
Where is the "set print area" button in Excel 2002 that was in Excel '97? =?Utf-8?B?Q2Fyb2wgTWM=?= wrote > Where is the "set print area" button in Excel 2002 that was in Excel '97? > Are you sure it was "standard"? Only way I could get in was to right-click the toolbar|Customise and drag it to the toolbar from Commands|File -- David ...

is it posible to keep the quick launch icons in a specific layout?
I have moved the task bar tot he right side of the screen. I have a number of applications which I have 'loaded' onto the quick launch section of the task bar. Now, aside from the fact that Microsoft seems to have different icons for it's products in Vista and XP (and the confusion that is causing), is the small minor detail that the vista task bar seems to reorganize at random. I've set up two columns of icons, with tasks "lumped" together in rows according to my own preferences. (mail washer next to the email program, the MP3 tag program next to ...

Outlook 2003
In Outlook 2003, #1 Is there a way to refresh the unread folder so that read messages no longer apear? Right now I have to click closed the unread folder and click it again #2 Is there a way to create a toolbar button that goes directly to a subfolder? Thanks ...

Report Can Grow not aligned horizontally
I have a report where I have 1 row of text, memo, number, and date fields. The memo field can contain up to 4-5 lines of wrapped text. I have set all teh rows to "can grow". However, on my report, the conditional formatting doesn't grow. For instance, the fill (which I have set to a gray color) in the memo field is about 3 lines deep when there is a lot of text in the memo field, but the text and number fields associated with that record are actually only 1 line. This essentially looks like a mess, small gray filled boxes for the text fields and a large gray ...

Why will my publisher 2003 not print graphics?
I have recently loaded windows 7, and since then I cannot print any graphics from any publisher document, text and infills print but lines do not! I have looked at the advance printer settings and the "Do not print any graphics" box is not ticked. I have also tried reloading publisher but this did nothing. Any ideas anyone? Might take a look at the web site of your printer model to see if there are Windows 7 drivers. Will the document print okay if you convert it to PDF? There are free converters around. www.primopdf.com is free. It is always wise to completely remove ...

Custom reports #3
Hi, I want to pull a report on how many customers I am getting every hour of the day. Does anyone out there know how to do that? I can try writing a query if someone can tell me which table I can find this information in (timestamp, transaction etc). Any help is appreciated. Regards JD This info is given at the end of the Z report. If you want to use it in a query open the Z report recipt file using the Notepad and see the fields that are used... Report.Hour.HourSales etc... Hope this helps... Carlos "JD" wrote: > Hi, > > I want to pull a report on how many cust...

How can I print on 8 1/2"x17" paper?
I have cut down an 11x17 paper to 8 1/2" x 17". I cannot figure out how to change the paper size to accept and print anything bigger than 14." any suggestions would be greatly appreciated First make the size settings in the Printer Setup. You may need to use the Custom selection. -- Don Vancouver, USA "mickilena" <mickilena@discussions.microsoft.com> wrote in message news:1AD99AFE-7FE7-4A07-9D20-1B1AFF9856BD@microsoft.com... >I have cut down an 11x17 paper to 8 1/2" x 17". I cannot figure out how to > change the paper size to accept a...

how to run onhand value report
I get the message enter parameter when entering the zoom feature On Sat, 6 Mar 2010 17:36:01 -0800, junebugg <junebugg@discussions.microsoft.com> wrote: >I get the message enter parameter when entering the zoom feature You'll have to give us some more context than that, junebugg. What's the "onhand value report"? What's the "zoom feature"? You can see your database; we cannot! -- John W. Vinson [MVP] ...

Fulfillment type orders
We have orders at the initial status (just entered) and the options to allow delete documents and void documents are enabled on the Sales Order Type. However, we can't get a void or delete button unless we move the fulfillment order through the confirm process to an "Invoice" to get a Delete? What's up with this? Very annoying. Jana, I know it is subtle and wish there was a better way to display it, but the Void option only applies to Invoice type IDs and not Fulfillment Order type IDs ("Void Invoice Documents" vs. "Delete Documents"). Since both t...

Print preview distorts objects
I have an XL2000 worksheet that has 4 controls on it (one command button, and 3 radio buttons). When I print preview the worksheet, once I close the print preview window the controls become distorted in size and location. Has anyone ever encountered anything like this? Thanks, Bill ...

Printing problem in booklet format
When I try to print my booklet document, on the screen it looks perfect, but when i go into print preview it only has half of each page on the paper. When i print, it comes out exactly like that. I have Publisher 2003 and run it on XP home. My printer is an Epson stylus Photo RX650. I contacted Epson and they say its a Publisher problem. Any suggestions. Driver? http://tech.epson.com.au/downloads/product.asp?sCategory=Multi_Functional&id=stylusphotorx650&FileType=1&EmailAdd=&MetricIDReturned=624915&platform=winxp Are you selecting booklet in page setup? Do you ...

Report: Cell #1, Cell #2, Cell #3, Cell #4
I am stuck again and would love som help :( I would like to repeat all words found inside ~25 cells, separated only by ", ", ignoring empty cells. Data: A1: [Apple ] A2: [Orange] A3: [Banana] A4: [Tomato] A5: [Syrup ] A6: [ ] A7: [ ] A8: [ ] The result should be something like: [Apple, Orange, Banana, Tomato, Syrup] -- JemyM ------------------------------------------------------------------------ JemyM's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26945 View this thread: http://www.excelforum.com/showthread.php?thre...

Departments on Z Report
Hello, I have noticed that as I set up new departments and categories into the database, the new departments are always printed last...or below all of the other departments. Is there a way to change this, and possibly have them organized alphebetically or in an order I would like? Thank You, Vicne Perhaps if you modified the department table usinfg Microsoft Access 2003 .... not that I would advise that :-) Vince... is this you... my buddy? Since you don't use an email address... I'm never sure if it you... and then I worry I'm getting too personal with someone I don'...

Printing a newsletter on 11x17 not in full size
I am trying to print my 4 page newlsetter that is 8.5x11 on 11x17 so that it is a folded newsletter. It prints on the 11x17 but it keeps printing small with crop lines. It is in the right order but not full size. PLEASE HELP What version Publisher? Are you using Publisher 2007? Are you setting up your printer first for 11 x 17? File, page setup, booklet, select custom size 8.5 x 11, click advanced on the right, select booklet in the pull down type 8.5 width 11 height -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Tam Nee...

How do I assign a name to a PDF report via VBA
Thanks to the internet site: http://msdn.microsoft.com/en-us/library/ee336132.aspx I have the following subprocedure: Private Sub Print_to_PDF_Click() On Error Resume Next Dim reportName As String reportName = "HCBS CMgr Smmry Report" DoCmd.OpenReport reportName, _ View:=acPreview, WindowMode:=acHidden Set Reports(reportName).Printer = _ Application.Printers("CutePDF Printer") DoCmd.OpenReport reportName, _ View:=acViewNormal End Sub This appears to be a good start; however, it stops and waits for me to enter the n...

How can I count unique values in a query in the report footer 12-16-07
I have a report that gives me the count of the status of individuals . This works fine as long is there is only one record in the query (in my query there is one record per month). When I query 12 months (individuals may appear in various months) it counts each record of an individual. For Example in a query considering 12 months for a widow Jones it may count her 12 times and for a survivor named Smith may count her 8 times: Widows 12 Survivors 8 I would like to add a count in the report footer that will tell me how many unique individuals I have in the report (Example widows: Tot...

Add message to customers on printed invoice
We should be able to add a message to customers (holiday hours, holiday message, etc.) to an invoice. Even QuickBooks has this ability, why doesn't GP? -- Art Cabot Director, Information Technology Sizemore, Inc. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. ht...

PRINT PREVIEW #6
I REVIEW A PRINT PREVIEW AND AM OK WITH IT. I SAVE THE FILE AND WHEN I RETRIEVE THE FILE THE NEXT DAY THE PRINT PREVIEW HAS CHANGED. WHAT IS HAPPENING? -- RON What has changed? -- Bernard Liengme www.stfx.ca/people/bliengme remove CAPS in email address "RON" <RON@discussions.microsoft.com> wrote in message news:0D42919B-91FE-4B88-B932-EC5E947BB035@microsoft.com... >I REVIEW A PRINT PREVIEW AND AM OK WITH IT. I SAVE THE FILE AND WHEN I > RETRIEVE THE FILE THE NEXT DAY THE PRINT PREVIEW HAS CHANGED. WHAT IS > HAPPENING? > -- > RON ...

printing problems with memorized reports
We have recently been running into printing problems with our memorized reports. We will print preview a report and it will look fine on screen, then we will send to the printer, and the report print extremely small in the corner of the page. However if we go back in and re-print the report then it will print normal size on the page. We are not making any settings changes at all, and when it does this appears to just be at random. We are printing to an HP laserjet 4000 series printer that is on our network. We've used RMS with the same configuration for approx. 5 years now and ...