UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Binding a report to a Recordset (object variable)    
 
   
stangfreak
post May 4 2006, 01:16 PM
Post #1

UtterAccess Addict
Posts: 121
From: CA



Hello,

This seems exceedingly simple, but I can't figure out how to do it. I have created a Recordset object variable, and populated the variable with the results from a pass-through query (so a SQL Server db). I would like to bind a report to the resulting recordset (in code).

Is this possible?

Thanks for your help!
Go to the top of the page
 
+
BrianS
post May 4 2006, 01:18 PM
Post #2

UtterAccess VIP
Posts: 5,597
From: St. Louis, MO



Why not just bind it to the pass through query?
Go to the top of the page
 
+
stangfreak
post May 4 2006, 01:20 PM
Post #3

UtterAccess Addict
Posts: 121
From: CA



I don't wish to save the PT query to disk
Go to the top of the page
 
+
stangfreak
post May 4 2006, 01:34 PM
Post #4

UtterAccess Addict
Posts: 121
From: CA



Maybe I should include the whys, just in case I'm missing something bigger.

1> I need to use a pass-thru query (I think) because I'm retreiving data from SQL server functions (I don't suppose there's any other way for Access to feed parameters to SQL functions, is there?)

2> I'd prefer not to save the PT query to disk partially to avoid clutter in my access db, and partially to avoid making the connect string (which will include the pw) easily retrievable
Go to the top of the page
 
+
BrianS
post May 4 2006, 01:48 PM
Post #5

UtterAccess VIP
Posts: 5,597
From: St. Louis, MO



Ok, fair enough

1. There is a way through ADO to pass parameters to SQL Server procedures.

Have a look here

2. You can set the Report's recordset property = to your recordset during Load

CODE
Dim cn as ADODB.Connection
Dim rs = ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

[color="green"]'A bunch of code here to configure/open your connection and recordset
'I am not sure if the recordset rs has to be open or not when you set Me.Recordset equal to it
'I would suspect that it would not have to be open.   [/color]

Me.Recordset = rs

[color="green"]'code to close your connection, rs and clean up memory[/color]
Go to the top of the page
 
+
stangfreak
post May 4 2006, 01:54 PM
Post #6

UtterAccess Addict
Posts: 121
From: CA



Access 97 (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
Go to the top of the page
 
+
BrianS
post May 4 2006, 02:34 PM
Post #7

UtterAccess VIP
Posts: 5,597
From: St. Louis, MO



ah crap, I did not see the forum, sorry for wasting your time with ADO. Give me a little time and I will see if I can cook up a DAO solution using query defs.
Go to the top of the page
 
+
stangfreak
post May 4 2006, 02:35 PM
Post #8

UtterAccess Addict
Posts: 121
From: CA



Ok, I think I'm gonna cheat. I'll create a view with a cross join, then just create a SQL statement with a where clause and bind the report to that in code. Icky.
Go to the top of the page
 
+
schroep
post May 4 2006, 03:04 PM
Post #9

UtterAccess VIP
Posts: 5,200
From: Denver, Colorado [USA]



Pretty sure you couldn't bind recordset variables to forms or reports in A97; I think that functionality first started to be introduced in A2000.
Go to the top of the page
 
+
BrianS
post May 4 2006, 03:09 PM
Post #10

UtterAccess VIP
Posts: 5,597
From: St. Louis, MO



Ok, I have something for you, not too difficult. Create query on the fly and delete it when the report closes. Its a little gross but best I can do with DAO

CODE
Private Sub Report_Close()

DelQuery

End Sub

CODE
Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Err

Dim qry As DAO.QueryDef
Dim prop As DAO.Property


Set qry = CurrentDb.CreateQueryDef("USysqryReport", "Select * from Account;")

[color="green"]'This is my ODBC Connection to an Oracle Database, yours will be different. I just created a pass through query from the designer and cut and pasted. [/color]
qry.Properties("Connect").Value = "ODBC;DSN=OracleODBC;UID=budget;PWD=budget;DBQ=MAINFRAME;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAl
lSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=0;"

[color="green"]'set any parameters you have here you wish here like this [/color]
qry.Parameters("some parameter name") = "Some value"

qry.Close
CurrentDb.QueryDefs.Refresh
Me.RecordSource = qry.Name

Report_Open_Exit:
    Set prop = Nothing
    Set qry = Nothing
Exit Sub

Report_Open_Err:
    MsgBox Err.Number & " " & Err.Description
    DelQuery
    Resume Report_Open_Exit


End Sub

CODE
Private Sub DelQuery()

On Error GoTo DelQuery_Err

DoCmd.DeleteObject acQuery, "USysqryReport"

DelQuery_Exit:
Exit Sub

DelQuery_Err:
    Select Case Err.Number
        Case 3011 [color="green"]'object does not exist [/color]
            Resume Next
        Case Else
            MsgBox Err.Number & " " & Err.Description
            Resume DelQuery_Exit
    End Select
End Sub
Go to the top of the page
 
+
BrianS
post May 4 2006, 03:10 PM
Post #11

UtterAccess VIP
Posts: 5,597
From: St. Louis, MO



Yes you are correct Peter, I looked for the that too at first. They did not add the Recordset property to Forms/Reports until ADO => Access 2000. I think what I posted will do as long as he already has an ODBC connection set up on each users' machine.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 02:07 AM