How to maximize a report preview window and fit report from VBA?

G

Guest

I want to open a report preview from a command button on a form and have the
report preview window maximize and the report fit the window. I can't
remember the way to fit the rport. Help, please.
 
M

Marshall Barton

David Semon said:
I want to open a report preview from a command button on a form and have the
report preview window maximize and the report fit the window. I can't
remember the way to fit the rport. Help, please.


Right after the DoCmd.OpenReport line in your form, add:

DoCmd.Maxiize
DoCmd.RunCommand acCmdSizeToFit
 
G

Guest

Thank you very much. Appreciate the help.

Marshall Barton said:
Right after the DoCmd.OpenReport line in your form, add:

DoCmd.Maxiize
DoCmd.RunCommand acCmdSizeToFit
 
G

Guest

Marshall:

Just tried your suggested code. Got an error message: 2046, "The command
or action "SizeToFit" isn't available now.

When I go to the debugger, the DoCmd.RunCommand acCmdSizeToFit line is
highlighted.

Any ideas that might help??

Dave
 
M

Marshall Barton

I had the wrong fit thingie. Try this:

DoCmd.OpenReport . . .
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
 
G

Guest

Marsh,

Just tried your last suggestion. Got the same error again. ????

BTW, where can I find a definition of the constants you are referring to?

Thanks for your help.

Dave

Marshall Barton said:
I had the wrong fit thingie. Try this:

DoCmd.OpenReport . . .
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
--
Marsh
MVP [MS Access]


David said:
Just tried your suggested code. Got an error message: 2046, "The command
or action "SizeToFit" isn't available now.

When I go to the debugger, the DoCmd.RunCommand acCmdSizeToFit line is
highlighted.
 
J

Jeff Conrad

David,

You may have missed this from Marsh's first post, but the code
he provided *must* be in the form that opens the report. This code
cannot be put in the report's Open event which it appears you
are doing. Move the code to the form that opens the report, such
as a command button's Click event.

--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html


in message:
Marsh,

Just tried your last suggestion. Got the same error again. ????

BTW, where can I find a definition of the constants you are referring to?

Thanks for your help.

Dave

Marshall Barton said:
I had the wrong fit thingie. Try this:

DoCmd.OpenReport . . .
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
--
Marsh
MVP [MS Access]


David said:
Just tried your suggested code. Got an error message: 2046, "The command
or action "SizeToFit" isn't available now.

When I go to the debugger, the DoCmd.RunCommand acCmdSizeToFit line is
highlighted.


I want to open a report preview from a command button on a form and have the
report preview window maximize and the report fit the window. I can't
remember the way to fit the rport.
 
G

Guest

Jeff: You are absolutely correct. I did put it in the report, not the form.
Moved the code to the form and it works great. Thanks.

Marsh: Thanks again for your help. I just didn't read closely enough.

Dave

Jeff Conrad said:
David,

You may have missed this from Marsh's first post, but the code
he provided *must* be in the form that opens the report. This code
cannot be put in the report's Open event which it appears you
are doing. Move the code to the form that opens the report, such
as a command button's Click event.

--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html


in message:
Marsh,

Just tried your last suggestion. Got the same error again. ????

BTW, where can I find a definition of the constants you are referring to?

Thanks for your help.

Dave

Marshall Barton said:
I had the wrong fit thingie. Try this:

DoCmd.OpenReport . . .
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
--
Marsh
MVP [MS Access]


David Semon wrote:
Just tried your suggested code. Got an error message: 2046, "The command
or action "SizeToFit" isn't available now.

When I go to the debugger, the DoCmd.RunCommand acCmdSizeToFit line is
highlighted.


I want to open a report preview from a command button on a form and have the
report preview window maximize and the report fit the window. I can't
remember the way to fit the rport.
 
M

Marshall Barton

David said:
BTW, where can I find a definition of the constants you are referring to?


There is nothing in Help, beyond a list of the constants.
Apparently, MS expects you to be able to determine the
meaning of the constant by correlating its name with the
corresponding menu item (where there is one, anyway).
Sometimes this is moderately adequate, but, as I just
demonstrated, often it is not.

AFAIK, the only source for an explanation of the constants
is at:
http://www.tkwickenden.clara.net/
 
G

Guest

Thank you. You have been most helpful. I was surprised to find what you did
-- the Help file does not define the constants. I guess Microsoft thinks we
are smarter than I am! The site you referenced looks very interesting.

Thanks again.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top