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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reports and parameter queries with VB6

Status
Not open for further replies.
Dec 1, 2002
2
0
0
US
I am trying to open access reports from my visual basic application. this in itself is not much of a problem, but there are some small problems i'd like to take care of.

first off, some of my reports are based on parameter queries. i'd like to pass these parameters to the reports automatically, but i'm not sure how to do it. i tried playing around with the OpenArgs argument of the OpenReports method, but I got a type mismatch. Is this where I put my parameter, or am i going in the wrong direction? if so, what format does it want to be in? here's a code snippet of what i'm trying:
objAccess.DoCmd.OpenReport "repCustomer Receipt", acViewPreview, "", "", "", Val(datAccountsReceivable.Recordset!customerid)

where the customerID field holds the data i want to pass as a parameter.

secondly, the way i'm doing this creates the potential for huge memory leaks. what i'm doing is creating an access.application object, setting it to my db, and then using DoCmd.OpenReport. this is all good and well, and if the user does what I want them to, then there are no problems. but if the user closes the access application, then an instance of the access process remains in memory even after using the Quit method and setting the object to nothing. Each instance uses about 12mb of memory, so it wouldn't take too many before a system would grind to a halt. what can I do to deal with this? my code follows.

Set objAccess = CreateObject("access.application")
objAccess.Visible = True
objAccess.OpenCurrentDatabase gcstrDatabase
objAccess.DoCmd.OpenReport strReportName, acViewPreview, "", ""
MsgBox "Click OK when done.", vbOKOnly
objAccess.Quit
Set objAccess = Nothing


also, i'm only using that message box to keep the report from immediately closing. is there a more graceful way to do this? if i can do away with this message box and deal with the memory leak issue at the same time that would be wonderful. any and all help will be greatly appreciated.

Mike
 
Hi,

I suggest to try not pass parameters but change the whole sql string of the query!!!!!

You have to use the DAO object (references), declare a QueryDef object, set up this object with the query what is the source of Your report and just change the SQL of the query!


In this way You don't have to use any parameter or variable.

Dim appl As Access.Application
Dim querDef As QueryDef

appl.OpenCurrentDatabase App.Path & "MyDB.mdb"

Set querDef = appl.CurrentDb.QueryDefs("MyQuery")

querDef.SQL = "SELECT....."

querDef.Close

appl.DoCmd.OpenReport "MyReport", acViewNormal

Tibi
 
thanks for the tip, tibi, that's exactly what i just did last night. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top