PDA

View Full Version : Run Crystal report through a command button



wasim_sono
04-24-2006, 06:21 AM
Dear all

I used the following code in creating command button wizard to run a crystal report but an error message display like

" Invalid procedure call or argument"

The code for command button is

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click
Dim stAppName As String
stAppName = "C:\Documents and Settings\wasim\My Documents\Pharmacy\Report1.rpt"
Call Shell(stAppName, 1)
Exit_Command28_Click:
Exit Sub
Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub


Can any one help me?


Regards.


Wasim

mbarron
04-25-2006, 07:07 AM
Try somthing like this:

Private Sub RunCrystal_Click()
On Error GoTo Err_RunCrystal_Click

Dim stAppName As String
Dim strFileName As String
strFileName = "C:\TheLocationOfYourReport\Report.rpt"
CreateObject("WScript.Shell").Run Chr(34) & strFileName & Chr(34)

Exit_RunCrystal_Click:
Exit Sub

Err_RunCrystal_Click:
MsgBox Err.Description
Resume Exit_RunCrystal_Click

End Sub

wasim_sono
04-26-2006, 03:58 AM
mbarron

I used ur code but it didn't give result. It only transfer the control to "My Computer" icon.Now my code is like this:
Private Sub Command29_Click()
On Error GoTo Err_Command29_Click
Dim stAppName As String
stAppName = "C:\Pharmacy\report1.rpt"
CreateObject("WScript.Shell").Run Chr(34) & strFileName & Chr(34)
'Call Shell(stAppName, 1)
Exit_Command29_Click:
Exit Sub
Err_Command29_Click:
MsgBox Err.Description
Resume Exit_Command29_Click

End Sub


Any suggestion please.

Wasim

XLGibbs
04-26-2006, 04:00 PM
Are you trying to access a crystal report from Access? or are you trying to launch the crystal report interface?

At my office we had to write a front end that would access the reports through a web based crystal application.

wasim_sono
04-26-2006, 09:42 PM
Gibbs

Actually I created an application in MS-ACCESS. for reports Im facing some problems in Access report. For this I used crystal report. Now I want that user should only click in switchboard item containing "Run report" icon. As user click the crystal report should run and as he close that report the control should back on switchboard.


Wasim

XLGibbs
04-27-2006, 05:23 PM
Iam not completely sure, but your code is wrong.

You fill the strAPPName in a variable, but the shell code on the next line refers to strFileName instead which may be why the code did not work.

Make sure the variable names are the same and try that code..should create the instance of Crystal you need. When the instance closes, Access should be back in charge.

wasim_sono
04-27-2006, 09:38 PM
O how I'm foolish. Gibbs: you are right. Some time we go into the deep even the last point but never look the tiny point in start. :banghead:

Now my code is working perfectly. :thumb
Thanks a lot of u and all the guys who helped me. :friends:


Regards.


Wasim