Solved

Access Pass Through Query

Posted on 2009-05-13
7
370 Views
Last Modified: 2013-11-28
I created a Pass Through query in Access that returns a result set in the open event of a report.  I believe the data is coming back correctly as it appears in my debug window but, now that i have the data i am not sure what to do with it.  How do i get the data from my querydef to my report recordsource?
Private Sub Report_Open(Cancel As Integer)
 
    Dim MyDb As DAO.Database, MyQry As QueryDef, MyRS As DAO.Recordset
    Set MyDb = CurrentDb()
    Set MyQry = MyDb.CreateQueryDef("")
 
    MyQry.Connect = "ODBC;DSN=DSNName;DATABASE=DBName"
    MyQry.SQL = "spApplicantFlow '05/01/2007', '04/30/2008'"
    
    MyQry.ReturnsRecords = True
    Set MyRS = MyQry.OpenRecordset()
    
    MyRS.MoveFirst
    Debug.Print MyRS!BranchName
    
    MyQry.Close
    MyRS.Close
    MyDb.Close
 
End Sub

Open in new window

0
Comment
Question by:trademark16
  • 4
  • 3
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24377548
trademark16,

Basically you need to set your "Records" as the "RecordSource for the report

The RecordSource can be something like:
SELECT CustID,CustName,CustCountry FROM tblCust WHERE Country='Spain';

JeffCoachman
0
 

Author Comment

by:trademark16
ID: 24377763
Not sure i understand.  I see that my RecordSet has data in it, but it's not a table that i can call.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24377877
I can't really decipher what you code is doing.

Dose his have to be a pass through query?

Can you first see that if a standard query will work, *then* try this as a Pass through query?

Can youy simply create a linked table from this source and create a report from this linked table?

JeffCoachman
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:trademark16
ID: 24377936
It has to be a pass through query because i need to use the "with (nolock)" option in my from cluase or the query will go to a SUSPENEDED status and never complete.  Cannot use nolock in a standard access query.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24378251
Specifically, how are you sure that the data is "Coming Back Correctly"?

Record Count, Record stream, SQL?
0
 

Author Comment

by:trademark16
ID: 24378310
Using the following code:

    MyRS.MoveFirst
    Debug.Print MyRS!BranchName

I moved to the first record and the Debug did display the BranchName that i was expecting.
0
 

Accepted Solution

by:
trademark16 earned 0 total points
ID: 24378770
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

829 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