Variable Question

  • Thread starter Thread starter Lillian
  • Start date Start date
L

Lillian

I need some help with this code that I need to use.
I hope it is easy enough to be understood.
The problem is I want to use a variable strTemp for the acViewPreview on
the DoCmd line below. I think it is the Dim that is causing a type
missmatch error.


Dim strTemp as string

RetValue = MsgBox("Preview Reports that have been checked? Click Yes to
Preview or No to Print", vbYesNo)
If RetValue = 6 Then
Set strTemp = acViewPreview
GoTo Continue
End If
Set strTemp = acViewNormal

Continue:

' DoCmd.OpenReport "rptEndOfMonthALL", acViewPreview
DoCmd.OpenReport "rptEndOfMonthALL", strTemp

GoTo Exit_Error_Click
 
Al said:
Lillian,
Try....
Dim strTemp as Variant
StrTemp = acViewPreview
(Tested OK)

But... I 'm not sure why your using a variable for acViewPreview, when a
simple IF statement (using acViewPreview) would do the trick just as
well... with no variable needed.

If RetValue = 6 Then
DoCmd.OpenReport "rptEndOfMonthALL", acViewPreview
Else
DoCmd.OpenReport "rptEndOfMonthALL", acViewNormal
End if

Why use a variable to represent only 1 value,,, just use the value itself.
It's a bit like saying 1=1.

Also, I think my code is much easier to read, and understand...
Your call though...



I got an "object required" error on the Set strTemp = acViewPreview line.

I have someother routines to do but this one thing has just got me stumped.

So, I wrote it as simple as I can.
 
Rob said:
Hi Lillian,

The problem is that acViewNormal is not a string value; it is a member of
the AcView class - essentially a built-in constant. You could declare it
as Long, and your code will work (if you remove "Set " from your variable
assignment). However, I'd suggest simplifying your code even more, as
follows (and using the defined constant vbYes to check the return value of
your MsgBox):

If MsgBox("Preview Reports that have been checked? Click Yes to
Preview
or No to Print", vbYesNo) = vbYes Then
DoCmd.OpenReport "rptEndOfMonthALL", acViewPreview
Else
DoCmd.OpenReport "rptEndOfMonthALL", acViewNormal
End If

HTH,

Rob


Thank You so much. It worked. Long with no Set did it.
 
Lillian,
Try....
Dim strTemp as Variant
StrTemp = acViewPreview
(Tested OK)

But... I 'm not sure why your using a variable for acViewPreview, when a
simple IF statement (using acViewPreview) would do the trick just as well...
with no variable needed.

If RetValue = 6 Then
DoCmd.OpenReport "rptEndOfMonthALL", acViewPreview
Else
DoCmd.OpenReport "rptEndOfMonthALL", acViewNormal
End if

Why use a variable to represent only 1 value,,, just use the value itself.
It's a bit like saying 1=1.

Also, I think my code is much easier to read, and understand...
Your call though...
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html
"Find a job that you love... and you'll never work a day in your life."
 
Hi Lillian,

The problem is that acViewNormal is not a string value; it is a member of
the AcView class - essentially a built-in constant. You could declare it as
Long, and your code will work (if you remove "Set " from your variable
assignment). However, I'd suggest simplifying your code even more, as
follows (and using the defined constant vbYes to check the return value of
your MsgBox):

If MsgBox("Preview Reports that have been checked? Click Yes to Preview
or No to Print", vbYesNo) = vbYes Then
DoCmd.OpenReport "rptEndOfMonthALL", acViewPreview
Else
DoCmd.OpenReport "rptEndOfMonthALL", acViewNormal
End If

HTH,

Rob
 
Al said:
Lillian,
Probably that's because you used the "Set", instead of just StrTemp =
acViewPreview.
I think it would be better if you just used the code I provided.


Yes it is simpler for one report.
I am using the code to print using only one report and one table. I now can
pull different records from the one table and print with one report.
Instead of making many reports I use strings and the do loop with case.

Yes I removed the Set and it worked with variant

Thanks
 
Back
Top