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!

Print Crystal report on Access DB!

Status
Not open for further replies.

wendywam

Programmer
Jun 21, 2004
15
ZA
Hi
This is what I have:

Const strLcQUERY_NAME As String = "AwbEnquirynull"
Const strLcQUERY_PARAMETER1_NAME As String = "StrName" ' This can be anything
Const strLcQUERY_PARAMETER2_NAME As String = "NodeType" ' This can be anything
Dim cmd As ADODB.Command: Set cmd = New ADODB.Command
Dim prm As ADODB.Parameter
Dim strLvDoB As String
With cmd
' Attach the command to a connection
.ActiveConnection = cnMvConnection
' Create the parameters (Name & Dob) which will be used
' by the query to insert
' Name, data type, parameter type, length of parameter, value of parameter
Set prm = .CreateParameter(strLcQUERY_PARAMETER1_NAME _
, adVarChar _
, adParamInput _
, Len(strName) _
, strName _
)
Call .Parameters.Append(prm)
' Name, data type, parameter type, length of parameter, value of parameter
Set prm = .CreateParameter(strLcQUERY_PARAMETER2_NAME _
, adVarChar _
, adParamInput _
, Len(NodeType) _
, NodeType _
)
Call .Parameters.Append(prm)
' Tell the command that it is about to execute a Query
.CommandType = adCmdStoredProc
' Tell the command the name of the query to be executed
.CommandText = strLcQUERY_NAME
' Execute the query
.Execute
End With

Report.WindowState = crptMaximized

Report.ReportFileName = "MyReport.RPT"
intTemp = Report.PrintReport

I do a similar thing in SQL Server and the report get printed.
I want to do the same thing with Access 97 DB. Is that possible?
Every time I try to run the code it says : Too few parameters. Expected two. This I guess is because the report does not get the parameters it is expecting.
My report depends on AwbEnquiry query.
Any suggestions guys.
 
Hey,

I dont know how class command functions. Below is some code I used to run a query with parameters.


Dim Db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef

Set Db = CurrentDb()
Set qdf = Db.QueryDefs("Team_Leader_Summary_Lines")

For i = 0 To Me.ListTLName.ItemsSelected.Count - 1
' Retrieve Team Leader Name
TLName = Me.ListTLName.ItemData(Me.ListTLName.ItemsSelected.item(i))
' Assign parameter to query def
qdf.Parameters("[TL Name]") = TLName
' Create record set
Set rst = qdf.OpenRecordset()
''do stuff with rst


Basically I run this query for each selected Name. The Name is the parameter. In this case I have used an existing querydef but you could do
qdf = db.CreateQueryDef(Stuff)
qdf.sql = "more Stuff"

Hope this helps in some way.

Mordja
 
.CommandText = strLcQUERY_NAME
* is this your stored procedure name? normally, prefix the name with the owner i.e. dbo.yourspname
' Execute the query
.Execute
End With

*Now you have executed the sp, does is create a recordset? and what do you plan to do with it?

Report.WindowState = crptMaximized

Report.ReportFileName = "MyReport.RPT"
intTemp = Report.PrintReport
 
Hi
I want to preview crystal report with the recordset result.
I need to pass parameters to the query that crystal report uses. I tried ODBC, inserted parameter fields on the report so that I get prompted to enter them when I preview the report. Nothing works. It does not even prompt for parameters. It only says Too few parameters, Expected two.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top