Calling Access to print a report


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Calling Access to print a report

  1. #1
    Bob Guest

    Calling Access to print a report


    Hi,

    Need one last bit of help on this project.

    I have a report in Access based on a query that I would like to print
    directly from VB.

    Having trouble figuring out the code that would simply print the report
    from Access when I click a print button.

    Any help with this code would be greatly appreciated.

    Thanks,
    Bob

  2. #2
    Russ Guest

    Re: Calling Access to print a report


    "Bob" <rgschumann@home.com> wrote:
    >
    >Hi,
    >
    >Need one last bit of help on this project.
    >
    >I have a report in Access based on a query that I would like to print
    >directly from VB.
    >
    >Having trouble figuring out the code that would simply print the report
    >from Access when I click a print button.
    >
    >Any help with this code would be greatly appreciated.
    >
    >Thanks,
    >Bob


    Bob,
    You can use Access' DoCmd object. You will need to set a reference to the
    Access Object Library, then try something like this:


    Private Sub Command1_Click()
    Dim Acc As Access.Application

    Set Acc = New Access.Application

    Acc.OpenCurrentDatabase ("C:\MyPath\MyDB.mdb")

    'acViewNormal will send the report to the printer immediately.
    Call Acc.DoCmd.OpenReport("My Report", acViewNormal)

    Acc.CloseCurrentDatabase

    Acc.Application.Quit acQuitSaveNone
    Set Acc = Nothing
    End Sub

    HTH,
    -Russ.


  3. #3
    Jo Guest

    Re: Calling Access to print a report


    "Russ" <russell.thompson@adlink.com> wrote:
    >
    >"Bob" <rgschumann@home.com> wrote:
    >>
    >>Hi,
    >>
    >>Need one last bit of help on this project.
    >>
    >>I have a report in Access based on a query that I would like to print
    >>directly from VB.
    >>
    >>Having trouble figuring out the code that would simply print the report
    >>from Access when I click a print button.
    >>
    >>Any help with this code would be greatly appreciated.
    >>
    >>Thanks,
    >>Bob

    >
    >Bob,
    >You can use Access' DoCmd object. You will need to set a reference to the
    >Access Object Library, then try something like this:
    >
    >
    >Private Sub Command1_Click()
    > Dim Acc As Access.Application
    >
    > Set Acc = New Access.Application
    >
    > Acc.OpenCurrentDatabase ("C:\MyPath\MyDB.mdb")
    >
    > 'acViewNormal will send the report to the printer immediately.
    > Call Acc.DoCmd.OpenReport("My Report", acViewNormal)
    >
    > Acc.CloseCurrentDatabase
    >
    > Acc.Application.Quit acQuitSaveNone
    > Set Acc = Nothing
    >End Sub
    >
    >HTH,
    >-Russ.
    >


    I have a related question. I'm working on a VB program which is already
    calling OpenReport with AcViewNormal, and it works well. But this seems
    to automatically use the default system printer. Our users want to select
    the printer themselves. I've tried a couple of ways to let them pick, the
    problem is both these methods automatically set the selected printer
    as the new default system printer.

    Is there a way to let the user pick, without altering the default printer
    selection? If not, how in Access, can I store the current default printer,
    let the user pick, print to that new printer, and then set the original
    printer as the default again?

    Any help is appreciated.

  4. #4
    Arthur Wood Guest

    Re: Calling Access to print a report


    Jo,
    Add the Common Dialog control to your project (Project/Component...Common
    Dialog Control).

    Then before the report is to be printed, add this line of code:

    CDialog1.ShowPrint

    which will disply the Printer Selection Dialog box, and allow the user to
    select ANY installed and accessible printer, to which the report will then
    be sent. This will NOT affect the user's current choice of Default Printer,
    unless they choose to make that change, on the Printer Dialog.

    Arthur Wood



    "Jo" <jwitt@genevasi.com> wrote:
    >
    >"Russ" <russell.thompson@adlink.com> wrote:
    >>
    >>"Bob" <rgschumann@home.com> wrote:
    >>>
    >>>Hi,
    >>>
    >>>Need one last bit of help on this project.
    >>>
    >>>I have a report in Access based on a query that I would like to print


    >>>directly from VB.
    >>>
    >>>Having trouble figuring out the code that would simply print the report
    >>>from Access when I click a print button.
    >>>
    >>>Any help with this code would be greatly appreciated.
    >>>
    >>>Thanks,
    >>>Bob

    >>
    >>Bob,
    >>You can use Access' DoCmd object. You will need to set a reference to

    the
    >>Access Object Library, then try something like this:
    >>
    >>
    >>Private Sub Command1_Click()
    >> Dim Acc As Access.Application
    >>
    >> Set Acc = New Access.Application
    >>
    >> Acc.OpenCurrentDatabase ("C:\MyPath\MyDB.mdb")
    >>
    >> 'acViewNormal will send the report to the printer immediately.
    >> Call Acc.DoCmd.OpenReport("My Report", acViewNormal)
    >>
    >> Acc.CloseCurrentDatabase
    >>
    >> Acc.Application.Quit acQuitSaveNone
    >> Set Acc = Nothing
    >>End Sub
    >>
    >>HTH,
    >>-Russ.
    >>

    >
    >I have a related question. I'm working on a VB program which is already
    >calling OpenReport with AcViewNormal, and it works well. But this seems


    >to automatically use the default system printer. Our users want to select
    >the printer themselves. I've tried a couple of ways to let them pick, the
    >problem is both these methods automatically set the selected printer
    >as the new default system printer.
    >
    >Is there a way to let the user pick, without altering the default printer
    >selection? If not, how in Access, can I store the current default printer,
    >let the user pick, print to that new printer, and then set the original
    >printer as the default again?
    >
    >Any help is appreciated.



  5. #5
    Paul Mc Guest

    Re: Calling Access to print a report


    G'day Jo.

    Take a look at the PrtDevMode report property in the Access VBA help. Should
    do the trick.

    Cheers,
    Paul

  6. #6
    AhTeck Guest

    Re: Calling Access to print a report


    "Russ" <russell.thompson@adlink.com> wrote:
    >
    >"Bob" <rgschumann@home.com> wrote:
    >>
    >>Hi,
    >>
    >>Need one last bit of help on this project.
    >>
    >>I have a report in Access based on a query that I would like to print
    >>directly from VB.
    >>
    >>Having trouble figuring out the code that would simply print the report
    >>from Access when I click a print button.
    >>
    >>Any help with this code would be greatly appreciated.
    >>
    >>Thanks,
    >>Bob

    >
    >Bob,
    >You can use Access' DoCmd object. You will need to set a reference to the
    >Access Object Library, then try something like this:
    >
    >
    >Private Sub Command1_Click()
    > Dim Acc As Access.Application
    >
    > Set Acc = New Access.Application
    >
    > Acc.OpenCurrentDatabase ("C:\MyPath\MyDB.mdb")
    >
    > 'acViewNormal will send the report to the printer immediately.
    > Call Acc.DoCmd.OpenReport("My Report", acViewNormal)
    >
    > Acc.CloseCurrentDatabase
    >
    > Acc.Application.Quit acQuitSaveNone
    > Set Acc = Nothing
    >End Sub
    >
    >HTH,
    >-Russ.
    >

    Hi,
    I've a project using Access97 and the code similar to the above worked very
    well, and I used the acViewPreview option.
    Recently, I converted the .mdb file to Access 2000.

    The conversion had some errors message:
    "There were compilation errors during the conversion or enabling of this
    database.
    The database has not been saved in a compiled state.
    The performance of this database will be impaired bacause Microsoft Access
    will need to recompile the database for each session."

    Inspite of this error, the vb code work just as well.
    Except the execution of the code similar to the above for previewing of reports
    don't work. I just cannot preview the report.
    Please help.
    BTW, I am using vb .exe instead of running from Access.

    AhTeck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center