|
-
May 25th, 2004, 02:11 PM
#1
Thread Starter
New Member
VB.NET --- Running a Paramaterized Query
I have a question regarding running an Access Report from VB.NET.
What I want to do is ......
Run a report created in Access from a VB.NET app (which I have done already), but using a paramaterized query.
I can create a Query in Access and asscoiate the report with that query BUT I need to be able to specify the criteria for the query on the fly.
How would I go about that. Like I said, I can set this in the qry builder of access, but I need to change the query search criteria dynamically)
Any help would be greatly appreciated. Details of what I am doing are below to help!!
What I have is this .....
-------------------------------
Below........
ReportQRY is the query I created in Access for testing. The query is as follows (SELECT *FROM historical_places WHERE M_Image_Name='1414'
In the properties of the report I associated the Recordsource Property with ReportQRY
I opened the Query then Opened the report. This works, BUT I just need to be able to run this query on the Report by specifying a value each time for (M_Image_Name) above, and not always keep it at 1414.
CODE
-------
Dim oAccess As New Access.Application
Dim sDBPath As String 'path to Northwind.mdb
Dim sReport As String
' Start a new instance of Access for Automation:
oAccess = New Access.Application
'My report name created within access
sReport = "Community"
'Path to the test Database
sDBPath = "C:\ReportServer\ReportDB\Test.mdb"
'Open the database
oAccess.OpenCurrentDatabase(filepath:=sDBPath, Exclusive:=False)
'Open the query created with MS Access
oAccess.DoCmd.OpenQuery("ReportQRY")
'Run the report (associated with the Query created in Access)
oAccess.DoCmd.OpenReport(sReport)
'Quit access
oAccess.Quit()
'Free
oAccess = Nothing
Many Thanks!!
-
May 26th, 2004, 10:28 AM
#2
Frenzied Member
To add a parameter to a query in Access, enclose the parameter prompt in square brackets.
VB Code:
(SELECT *FROM historical_places WHERE M_Image_Name = [Enter a value, sport]
If you do this in the query in Access, it'll prompt the user for a value.
If you want to pass the value in by code, that would be different.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|