Solved

Passing Parameter to Access Report in VB.Net?

Posted on 2008-06-17
3
1,128 Views
Last Modified: 2013-11-28
To test this procedure I hard coded the parameters into the query (in test.mdb).  Everthing works so far.   Now, I want to make it dynamic so I can pass the parameters at runtime.  

Do I need the dao object reference in project?  I am trying to stick with the .net exclusively.

The query name is prMemoSingle and I have two parameter mID and pID.   I am not sure how to access/pass these parameters so that I can make this code dynamic.

Secondly, does this code appropriately close/release the lock on the database?

        oAccess.CloseCurrentDatabase()
        oAccess = Nothing

Thanks!

Dim oAccess As Access.Application

        oAccess = New Access.ApplicationClass()

        oAccess.OpenCurrentDatabase(filepath:="s:\database\test.mdb", Exclusive:=False)

 

'---->  Open Access Query, pass parameters that the report is based upon.   Parameter 1 = mID, Paramter 2 = pID (both integers)

 

        oAccess.DoCmd.OpenReport(ReportName:="prMemoSingle", View:=Access.AcView.acViewNormal)

        oAccess.CloseCurrentDatabase()

        oAccess = Nothing

Open in new window

0
Comment
Question by:rrowe68
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 21805489
This is a guess based off how similar that looks to how you do it in VBA.
Dim oAccess As Access.Application

        Dim strCriteria as String

        oAccess = New Access.ApplicationClass()

        oAccess.OpenCurrentDatabase(filepath:="s:\database\test.mdb", Exclusive:=False)

 

'---->  Open Access Query, pass parameters that the report is based upon.   Parameter 1 = mID, Paramter 2 = pID (both integers)
 

    strCriteria = "[mID] = " & MymIDValue & " And [pID] = "  & MypIDValue   
 

    oAccess.DoCmd.OpenReport(ReportName:="prMemoSingle", View:=Access.AcView.acViewNormal, WhereCondition = strcritera)

 

        oAccess.CloseCurrentDatabase()

        oAccess = Nothing

Open in new window

0
 

Author Comment

by:rrowe68
ID: 21806774
Thanks Jimpen -- You are right.

Answer -- below


        Dim oAccess As New Access.ApplicationClass()

        Dim strWhere As String

        Try

            oAccess.OpenCurrentDatabase(filepath:="s:\database\emery.mdb", Exclusive:=False)

            strWhere = "nMemoID = " & CURRMEMO & " AND " & "lPropertyID = " & CURRPROP

            oAccess.DoCmd.OpenReport(ReportName:="prMemoSingle", View:=Access.AcView.acViewNormal, WhereCondition:=strWhere)
 

        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Critical)

        Finally

            oAccess.Quit()

            oAccess = Nothing
 

        End Try

Open in new window

0
 
LVL 38

Expert Comment

by:Jim P.
ID: 21806791
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now