How do I open an access 2002 report in a VB6 program?

webnso
webnso used Ask the Experts™
on
hello,

I am trying to open an access 2002 report named Station Log in a VB6 program. I would like to preview it within access and then be able to print it from access. I am NOT interested in using a data report, I have tried it and dont like it. The access report is much easier to format and program.

The code I am currently using works fine in that it will print the report, but it will not preview it for me first. I really do not understand what part of this code is causing it to print either, but it does print.

Private Sub cmdTurnover_Click()

Dim acc As New Access.Application
acc.OpenCurrentDatabase filepath:=strDBname_Active
acc.DoCmd.OpenReport Reportname:="Station Log",
View:=acViewNormal

End Sub

Thanks,
Chuck
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
View:=acViewPreview     'opens the report in preview mode
View:=acViewNormal       'prints the report


Steve

Commented:
-->"I am NOT interested in using a data report, I have tried it and dont like it. The access report is much easier to format and program.<--

You need to have Access installed on all client machines if you create an application containing an Access report for these reports to work. Are you ready with this scenario?

Commented:
-->"The code I am currently using works fine in that it will print the report, but it will not preview it for me first. I really do not understand what part of this code is causing it to print either, but it does print." <--

Sounds like Access is installed and printing fine.

but it will not preview it for me first <-- View=acPreview
what part of this code is causing it to print either, but it does print. <-- View:=acNormal


Steve
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hello,

I have changed the code from acViewNormal to acViewPreview but nothing appears. I don't know what is not working. Is there a show or visible command that is required?

Chuck

Commented:
Dim acc As New Access.Application
acc.OpenCurrentDatabase filepath:=strDBname_Active
Application.Visible = True
acc.DoCmd.OpenReport Reportname:="Station Log",View:=acViewPreview

Steve

Author

Commented:
Hi Steve,

I tried the last code you posted

Dim acc As New Access.Application
acc.OpenCurrentDatabase filepath:=strDBname_Active
Application.Visible = True
acc.DoCmd.OpenReport Reportname:="Station Log",View:=acViewPreview


and I got a runtime error '429' "activex component cant create object" and it stopped on this line of code:

Application.Visible = True

Any ideas?

Thanks,
Chuck

Author

Commented:
Steve,

This code works, but it opens access and the report in small windows. How do I make it open fullscreen?

Dim acc As New Access.Application
acc.OpenCurrentDatabase filepath:=strDBname_Active
acc.Visible = True
acc.DoCmd.OpenReport Reportname:="Station Log",View:=acViewPreview


Thanks,
Chuck
Commented:
Dim acc As New Access.Application
acc.OpenCurrentDatabase filepath:=strDBname_Active
acc.DoCmd.Maximize
acc.Visible = True
acc.DoCmd.OpenReport Reportname:="Station Log",View:=acViewPreview

Steve

Author

Commented:
Hi Steve,

The report window is now maximized within the access window, but access is not maximized. Can you show me how to do that as well?

This is last question then I will accept and award points.

Thanks,
Chuck

Commented:

Private Const SW_SHOWMAXIMIZED = 3
Private Declare Function ShowWindow Lib "User32" (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long

Dim acc As New Access.Application
Dim lngRet As Long

acc.OpenCurrentDatabase filepath:=strDBname_Active
lngRet = ShowWindow(hWndAccessApp, SW_SHOWMAXIMIZED)
acc.DoCmd.Maximize
acc.Visible = True
acc.DoCmd.OpenReport Reportname:="Station Log",View:=acViewPreview

Steve

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial