Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Crystal Reports FROM Access

Status
Not open for further replies.

valgore

Technical User
Nov 12, 2008
180
US
Hi, i am running an Access 2003 executable and i have made 3 reports in Crystal and i want to have a button that opens the Crystal Report application and run the report. i dont want the crystal report to run IN access, i want a button that opens a report in Crystal.

i have this Common Dialog code:

Code:
Option Compare Database

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Function LaunchCD(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
      "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = "C:\"
    OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
        If lReturn = 0 Then
            MsgBox "A file was not selected!", vbInformation, _
              "Select a file using the Common Dialog DLL"
         Else
            LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
         End If
End Function

i've seen many people use this to import excel spreadsheet. i was wondering if i could use this code to do what i am looking for.

Any help would be much appreciated.

Valgore
 
I have a form in 2003 that does that. I created a button and entered the report name in the hyperlink address property of the button.
Hope that helps.
 
ok. well i have 3 reports, and id rather not have 3 different buttons. any other suggestions?
 
How about using the ShellExecute API and passing the path to the .rpt file in? That should open it in Crystal for you (assuming Crystal is the default for rpt files on your machine).

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
wow. never heard of shellexecute API before. guess i have some reading to do :). thanks HarleyQuinn
 
ok so i found this code:

Code:
Option Explicit

'========================================================
'   API declaration
'========================================================
Private Declare Function ShellExecute _
    Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
    Dim sFile As String
    Dim sCommand As String
    Dim sWorkDir As String
    
    sFile = "C:\albums\index.html"  'The file to execute
    sCommand = vbNullString         'Command line parameters
    sWorkDir = "C:\albums"          'The working directory

    ShellExecute hwnd, "open", sFile, sCommand, sWorkDir, 1
End Sub

but i get Compile Error: Sub or Function not defined and it is pointing to ShellExecute. i put
Code:
Option Explicit

'========================================================
'   API declaration
'========================================================
Private Declare Function ShellExecute _
    Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
into a module and the rest on a onclick. any ideas?
is this the right code?

Valgore
 
Why not simply use the FollowHyperlink method ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry i havent gotten back to you sooner, our office was robbed and i lost my computer.... anyways i looked at FollowHyperlink and that looks like what i want. but my question is i have 3 reports that i made. i need the user to be able to select which report to open, and then open that within Crystal. is that possible?

Valgore
 
so i added a Common Dialog module that lets me chose a file. the file path then goes to a textbox. so then how do i tell it to open the hyperlink in the textbox with a certain program?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top