?
Solved

Passing Parameter to Access Report in VB.Net?

Posted on 2008-06-17
3
Medium Priority
?
1,178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

765 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