Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2003, 01:22 PM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default open Access report from VB6

Hi,

 I'm accessing my Access Databse from VB6, all my forms are made in VB , but I want to know if it's possible to open my reports made in Access from Visual Basic, and what is the code ??

Thanks

 
Old October 31st, 2003, 10:21 AM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One way to do this is by using Snapshot Viewer (free download search internet for snpvw90). This can be used to view access reports that have been saved in Snapshot format.

You can then automate the Snapshot creation from VB as below....
(you will need to reference the Microsoft Access Library)

'Set variable for Access Application
Dim appAccess As New Access.Application

'Open Database
appAccess.OpenCurrentDatabase <Your Database Path as string>, True

'Open report
appAccess.DoCmd.OpenReport <Your Report Name as string>, acViewPreview

'Output in snapshot format to a temp file (should open in snapshot viewer automatically)
appAccess.DoCmd.OutputTo acOutputReport, <Your Report Name as string>, "Snapshot Format", "c:\temp.snp", True

'Quit access
appAccess.Quit

'Free
Set appAccess = Nothing

Hope this helps.



 
Old November 12th, 2003, 12:28 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi GHolden,

I used your advise that you gave to submit. It works great for the most part, but I have one problem with it and maybe you could help me out.

I'm using VB6 and Access 2000. In order for the datasource that I'm using in my VB6 program to recognize the database I have converted my database to a previous version. Everything runs exactly the way I want it except the fact that when I pull up my report (using the above snapshot way)on a different computer it doesn't show it with a "legal" page size like I specified in the report layout. It defaults to "letter" size and cuts off part of my report.

If I convert the database back to 2000, make the page layout on "Legal" size again, and convert back to previous version the report displays fine on the new computer. But the old computer that used to show it fine now shows it in "letter" and cut off.

Any idea on how to insure it displays on "legal" paper size to matter what computer I'm using would be greatly appreciated.

Thanks
Seagryphon
 
Old November 12th, 2003, 12:34 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are on a network, use the same default network printer for both databases. This also drives me nuts
:(



Sal
 
Old November 13th, 2003, 12:34 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I found this code in a book

################################################## ######

Public mobjAccess As Application


Private Sub cmdPrint_Click()

    Dim intCounter As Integer
    Dim intPrintOption As Integer

    If optPreview.Value = True Then
        intPrintOption = acViewPreview
    ElseIf optPrint.Value = True Then
        intPrintOption = acViewNormal
    End If

    mobjAccess.Visible = True
    For intCounter = 0 To lstReports.ListCount - 1

        If lstReports.Selected(intCounter) Then
            mobjAccess.DoCmd.OpenReport _
            ReportName:=Me.lstReports.List(intCounter), _
            View:=intPrintOption
        End If
    Next intCounter
End Sub
'____________________________________________
Private Sub cmdSelectDatabase_Click()

    dlgCommon.Filter = "*.mdb"
    dlgCommon.ShowOpen

        Me.txtSelectedDB = _
            dlgCommon.FileName
        Call ListReports
End Sub
'________________________________
Private Sub ListReports()

    Dim vntReport As Variant

    If mobjAccess Is Nothing Then
        Set mobjAccess = New Access.Application
    End If

    mobjAccess.OpenCurrentDatabase (Me.txtSelectedDB)

    lstReports.Clear
    For Each vntReport In mobjAccess.CurrentProject.AllReports
        lstReports.AddItem vntReport.Name
    Next vntReport
End Sub
################################################## ######

Remember that for both ways, the user running this code must have MS Access installed on their computers. I would rather view the report myself before printing it or sending it to a snapshot. You can actually distribute an mde file for reports with your VB app.



Sal
 
Old July 2nd, 2004, 11:34 PM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bradis86
Default

what library do you have to reference, and can this same process work for access forms?

 
Old July 4th, 2004, 04:19 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Reference the MAcceslibrary. Whatever the latest version of MAcceslibraty that your users haveJust remember that your users will also need ot haave access intalled on their pc, so the library you use must be the same library they use on their version of ms access.

Yes, I guess you could use this also for access forms, but Shy would you want to open an access form from vb? Going backwards from vb to access doew not make sense.



Sal
 
Old December 6th, 2005, 04:04 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Update on the Access Snapshot viewer. It has changed names and be downloaded from Microsoft for all versions of Access here:
http://www.microsoft.com/downloads/t...splayLang%3den

I found this posting very useful. Thanks! :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Open PDF within vb6 Jade08 VB How-To 6 May 14th, 2008 10:50 AM
Open mde or mdb access file from vb6 gorgo Pro VB 6 1 February 20th, 2006 01:39 AM
Using VB6 SP2 to Open Access 2003 .mdb DWSTERRETT VB Databases Basics 1 June 13th, 2005 08:24 AM
Open Access report object in ASP eapsokha Classic ASP Databases 2 March 31st, 2004 11:26 PM
load report from access to vb6 kclau VB Databases Basics 0 August 20th, 2003 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.