Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / September 2007

Tip: Looking for answers? Try searching our database.

Variable Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lillian - 13 Sep 2007 02:05 GMT
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 Campagna - 13 Sep 2007 04:51 GMT
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...
Signature

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

>I need some help with this code that I need to use.
> I hope it is easy enough to be understood.
[quoted text clipped - 18 lines]
>
>     GoTo Exit_Error_Click
Lillian - 13 Sep 2007 03:12 GMT
> Lillian,
>   Try....
[quoted text clipped - 17 lines]
> 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.
Al Campagna - 13 Sep 2007 14:55 GMT
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.
Signature

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

>> Lillian,
>>   Try....
[quoted text clipped - 25 lines]
>
> So, I wrote it as simple as I can.
Lillian - 14 Sep 2007 00:23 GMT
> 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
Rob Parker - 13 Sep 2007 04:58 GMT
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

>I need some help with this code that I need to use.
> I hope it is easy enough to be understood.
[quoted text clipped - 18 lines]
>
>     GoTo Exit_Error_Click
Lillian - 13 Sep 2007 03:26 GMT
> Hi Lillian,
>
[quoted text clipped - 39 lines]
>>
>>     GoTo Exit_Error_Click

Thank You so much.  It worked.  Long with no Set did it.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.