CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2005
    Location
    Cebu City Philippines
    Posts
    64

    viewing and printing ms access reports

    is there a way to view and print an ms access report?
    whats the code? please help me!

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: viewing and printing ms access reports

    Quote Originally Posted by matthewivan
    is there a way to view and print an ms access report?
    whats the code? please help me!
    The easiest way would be to use the Access Object (Remember the machine should have MS Access installed on it)
    Code:
        Dim oAccess As Access.Application
        Set oAccess = New Access.Application
        oAccess.OpenCurrentDatabase ("D:\db1.mdb")
        oAccess.Visible = True
        oAccess.DoCmd.OpenReport ReportName:="myReport", View:=acViewNormal

  3. #3
    Join Date
    Dec 2005
    Location
    Cebu City Philippines
    Posts
    64

    Re: viewing and printing ms access reports

    where shall i put the code? i put the code in a command button then an error occur User type not defined? how to solve this problem?
    where sohuld i put the code?
    Last edited by matthewivan; January 3rd, 2006 at 04:56 PM.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: viewing and printing ms access reports

    Quote Originally Posted by matthewivan
    where shall i put the code? i put the code in a command button then an error occur User type not defined? how to solve this problem?
    where sohuld i put the code?
    Are you using a Password Protected Database? And Does it give you an error on this statement
    Code:
    oAccess.OpenCurrentDatabase ("D:\db1.mdb")
    If you have a password protected database then you would need to change the open statement
    Code:
    oAccess.OpenCurrentDatabase "D:\db1.mdb", , "password"

  5. #5
    Join Date
    Dec 2005
    Location
    Cebu City Philippines
    Posts
    64

    Re: viewing and printing ms access reports

    no im not using a password protected database the error occur in the Dim oAccess As Access.Application statement
    --->User-defined type not defined

    heres the whole code

    Private Sub Command1_Click()
    Dim oAccess As Access.Application ----> error occur here says that "User-defined type not defined"
    Set oAccess = New Access.Application
    oAccess.OpenCurrentDatabase ("D:\db1.mdb")
    oAccess.Visible = True
    oAccess.DoCmd.OpenReport ReportName:="myReport", View:=acViewNormal
    End Sub

    what does this mean?

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: viewing and printing ms access reports

    Oh thats my Mistake. You need to add a reference to Microsoft Access 10 Object Library. Go to Project -->References and select Microsoft Access 10 Object Library. Then this code should work properly.

  7. #7
    Join Date
    Dec 2005
    Location
    Cebu City Philippines
    Posts
    64

    Re: viewing and printing ms access reports

    i've tried it but i'm using ms access 9.0 its okay now but when i tried it it directly print the report without previewing it. how to first preview it thank you very much

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: viewing and printing ms access reports

    Quote Originally Posted by matthewivan
    i've tried it but i'm using ms access 9.0 its okay now but when i tried it it directly print the report without previewing it. how to first preview it thank you very much
    Just change the View option of the report to acViewPreview.
    Code:
    oAccess.DoCmd.OpenReport ReportName:="myReport", View:=acViewPreview

  9. #9
    Join Date
    Nov 2005
    Posts
    36

    Re: viewing and printing ms access reports

    I'm so glad I stumbled across this thread. It answered a huge question for me But it gave me another.

    Code:
        Dim oAccess As Access.Application
        Set oAccess = New Access.Application
        oAccess.OpenCurrentDatabase ("D:\db1.mdb")
        oAccess.Visible = True
    'I added this to maximize the report within the Access window
        oAccess.DoCmd.Maximize
    'can you do something to maximize the window too? If not that's fine.
        oAccess.DoCmd.OpenReport ReportName:="myReport", View:=acViewNormal
    I'm sure it's not possible, but I have to ask. Is there a way to bring up the report without opening Access at all.

    I am using an ADODB connection for everything else in my app.

    Thanks a bunch

    Buddy

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: viewing and printing ms access reports

    Well I have never tried using Access Reports im my projects. So I actually never researched about this. But you could probably search on Google and if you are lucky you might get some nice samples.

    Also try exploring ADOX. There might be some option of showing Access Reports there. Right now I don't have time, but if I find something I'll post it here.

    Right now this is the only option I have.

  11. #11
    Join Date
    Nov 2005
    Posts
    36

    Re: viewing and printing ms access reports

    I actually got everything to work how I wanted for the most part. I had to manually resize my Access window, but now everytime the report opens the window stays the same size. I'm satisfied with that.

    I might try exploring ADOX, but this project has taken a great deal of exploring ADODB, I need a break.. lol

    Thanks a lot for your help Shuja

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured