Problems in Access 2007, but not 2003 (1 Viewer)

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
Hi,

Two years ago I released a an Access 2003 program to my client. Now they want to upgrade to 2007.

I got everything working in 2007 except this little bit of code:

DoCmd.RunCommand (acCmdPrintPreview)

It gives me the vague answer that "The command or action "PrintPreview" is not available now".

Is there an other method that I should know about?

This worked in 2003 ... has something changed? I tried removing the brackets.

Much appreciated help is necessary.
 

vbaInet

AWF VIP
Local time
Today, 16:56
Joined
Jan 22, 2010
Messages
26,374
This is for a report I believe? When you perform the Docmd.OpenReport command open it in print preview mode instead:

DoCmd.OpenReport "ReportName", acViewPreview
 

boblarson

Smeghead
Local time
Today, 08:56
Joined
Jan 12, 2001
Messages
32,059
This is for a report I believe? When you perform the Docmd.OpenReport command open it in print preview mode instead:

DoCmd.OpenReport "ReportName", acViewPreview

I'll just add that this is the correct code to use and the other RunCommand code that you were using Martyh is not really the code you should have been using for that.
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
Thanks for the quick response.

I just want to add that I'm trying to execute a sort of "print screen" (which previously worked with 2003 -- but apparently not with 2007! ) I'm trying to match the output of the 2003 version with the 2007 version -- a "Print Screen". I do not have a "Reportname" for that reason.
 

vbaInet

AWF VIP
Local time
Today, 16:56
Joined
Jan 22, 2010
Messages
26,374
Your method is used for Print Previewing a report and it still does perform the same function in 2007. However, the correct way to print preview a report is using the Docmd.Openreport method. I would have thought the acCmdPrintPreview command would also perform a print preview of a report (only) in 2003. I will test it out later.

From what you said, this isn't what you're after. Could you please explain what you mean by "a sort of print screen"? A print screen of what kind of object? Do you save a copy of that screen? Maybe have a look at the Docmd.OutputTo method.
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
Yes I believe the Docmd.Openreport method works; except that you need a report name to open and I do not have one because it is a "Screen Print". In 2003, you just
did

DoCmd.RunCommand (acCmdPrintPreview)

to get that screen print. However, in 2007 things have somehow changed.

I will check out the Docmd.OutputTo method.

Thanks again for your help.
 

boblarson

Smeghead
Local time
Today, 08:56
Joined
Jan 12, 2001
Messages
32,059
Yes I believe the Docmd.Openreport method works; except that you need a report name to open and I do not have one because it is a "Screen Print".
I still don't get it. Where is this "screen print" coming from and how does DoCmd.RunCommand (acCmdPrintPreview) allow you to print a screenshot? Does this exist only on the clipboard (from clicking PrtScn) or are you talking about something else?

Can you elaborate on what you are talking about?
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
The DoCmd.RunCommand (acCmdPrintPreview) allows you to print the screen (eg emulate hitting the Alt+Ctrl+"Print Screen" button) but it does a preview of the print before printing... At least it did for me in 2003 version. However things have changed some how in 2007.

I already have the report printout on another button that has the full report and thats fine... they also like the "quick and dirty" method method of just the "screen print" ... I'm assuming they want show their customers, or a colleague something.

I haven't yet tried the OutputTo method... Stay tuned...

Regards,
 

boblarson

Smeghead
Local time
Today, 08:56
Joined
Jan 12, 2001
Messages
32,059
You say it worked in 2003 but so far I haven't been able to make it work here with our 2003. That is why I'm a bit confused.

And yes, 2007 tightened up on some things so you are likely going to have to find another screen print solution.
 

vbaInet

AWF VIP
Local time
Today, 16:56
Joined
Jan 22, 2010
Messages
26,374
There must be some other line of code that somehow mimicks a print screen.
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
There it is, my simple code. Should work on any any form. All you need is a button named "cmdPrint" It was quite a while ago that I did the original code in A2003, and I don't have a A2003 on hand to compile but this is the original code that worked!


Code:
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click


    DoCmd.RunCommand (acCmdPrintPreview)

Exit_cmdPrint_Click:
    Exit Sub

Err_cmdPrint_Click:
    MsgBox err.Description
    Resume Exit_cmdPrint_Click
    
End Sub
 

vbaInet

AWF VIP
Local time
Today, 16:56
Joined
Jan 22, 2010
Messages
26,374
It's apparent there's no other code there.

Are you saying that if I were to run your cmdPrint function, open Paint or a Word application and Paste it in there I will get an image of the screen copied?

Did the SendKeys link not work?
 

boblarson

Smeghead
Local time
Today, 08:56
Joined
Jan 12, 2001
Messages
32,059
There it is, my simple code. Should work on any any form. All you need is a button named "cmdPrint" It was quite a while ago that I did the original code in A2003, and I don't have a A2003 on hand to compile but this is the original code that worked!


Code:
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click


    DoCmd.RunCommand (acCmdPrintPreview)

Exit_cmdPrint_Click:
    Exit Sub

Err_cmdPrint_Click:
    MsgBox err.Description
    Resume Exit_cmdPrint_Click
    
End Sub

Sorry, but I had to laugh when I tried this. This is NOT a Screen Print. It is only viewing the form in Print Preview, which is available using this code:

DoCmd.OpenForm Me.Name, acPreview


It is just viewing the form in print preview mode NOT making a screen print.
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
No ! It's just an emulation for the "Print Screen" however it did have the functionality of a print screen - just with the "Print Preview" in between -- you view the form in print preview mode and if you elect to print that out you will get a print screen.
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
Just as I stated "you view the form in print preview mode and if you elect to print that out you will get a print screen."

... but

DoCmd.OpenForm Me.Name, acPreview

does NOT work for me in 2007 !!
 

vbaInet

AWF VIP
Local time
Today, 16:56
Joined
Jan 22, 2010
Messages
26,374
"Print Screen" as we know it is taking a Copy of your screen which is saved in the Clipboard. That's what has been confusing us here. If your screen doesn't get saved to the Clipboard then it's not a print screen.

So are you running your 2003 database in 2007 or did you actually perform a conversion from 2003 to 2007?
 

Martyh

Registered User.
Local time
Today, 11:56
Joined
May 2, 2000
Messages
196
No I am right now running an ACCDB ... previously I ran an MDB first in 2003 (~ 2 yrs ago) and then in 2007 (~ 6 - 8 months ago).

I also said that it was "sort of " a "Print Screen"... I am not a Computer Programmer in the strictest sense of the word. But I try hard... :)
 

boblarson

Smeghead
Local time
Today, 08:56
Joined
Jan 12, 2001
Messages
32,059
The code I provided will do exactly the same thing.
 

Users who are viewing this thread

Top Bottom