|
-
Nov 8th, 2006, 09:41 AM
#1
Thread Starter
Hyperactive Member
PassThrough Query
I am using Access 2003 for a user gui and the original data is pulled from Oracle.
I need to lower the processing time and would like to write a pass through query to retreive the information via VBA/VB code behind an access form
I have queried this forum an I have only located a version using ADO but it really didn't focus on the query itself or maybe it does and I just do not undersstand all it says.
does anyone have any suggestions or references for me to look at?
This is what I have located currently:
VB Code:
Public Sub PassThroughADO(ByVal strQdfName As String, _
ByVal strSQL As String, _
Optional varConnect As Variant, _
Optional fRetRecords As Boolean = True)
' strQdfName is the name of the query
' strSQL is the new SQL string, if you need to update the original query
' varConnect is the optional connection string, probably need this
' fRetRecords Optional returns records defaults to True(or yes, what you want)
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
' Open the catalog
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = cn
' Get the command to fire
'here the string parameter of the query name is passed
Set cmd = cat.Procedures(strQdfName).Command
' set pass-through properties
cmd.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
' Update the SQL, or what to select from the query
cmd.CommandText = strSQL
' Update the Connection string, make sure we successfully get through
'your SQL Server
If Not IsMissing(varConnect) Then
cmd.Properties _
( "Jet OLEDB:Pass Through Query Connect String") = CStr(varConnect)
End If
' Update the ReturnsRecords property
' to return or NOT return records
cmd.Properties( _
"Jet OLEDB:Pass Through Query Bulk-Op") = Not fRetRecords 'or fRetRecords
' Save the changes you have fired
Set cat.Procedures(strQdfName).Command = cmd
'Clean up variables
Set cmd = Nothing
Set cat = Nothing
Swoozie
Somedays you just should not get out of bed.
-
Nov 9th, 2006, 07:37 AM
#2
Thread Starter
Hyperactive Member
Re: PassThrough Query
Good morning! Is there anyone familiar with this topic?
Swoozie
Somedays you just should not get out of bed.
-
Nov 9th, 2006, 07:52 AM
#3
Re: PassThrough Query
 Originally Posted by swoozie
Good morning! Is there anyone familiar with this topic?
Found these during a quick Google Search:
Search 1
Search 2
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Nov 9th, 2006, 09:20 AM
#4
Hyperactive Member
Re: PassThrough Query
 Originally Posted by swoozie
I am using Access 2003 for a user gui and the original data is pulled from Oracle.
I need to lower the processing time and would like to write a pass through query to retreive the information via VBA/VB code behind an access form
I have queried this forum an I have only located a version using ADO but it really didn't focus on the query itself or maybe it does and I just do not undersstand all it says.
does anyone have any suggestions or references for me to look at?
This is what I have located currently:
VB Code:
Public Sub PassThroughADO(ByVal strQdfName As String, _
ByVal strSQL As String, _
Optional varConnect As Variant, _
Optional fRetRecords As Boolean = True)
' strQdfName is the name of the query
' strSQL is the new SQL string, if you need to update the original query
' varConnect is the optional connection string, probably need this
' fRetRecords Optional returns records defaults to True(or yes, what you want)
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
' Open the catalog
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = cn
' Get the command to fire
'here the string parameter of the query name is passed
Set cmd = cat.Procedures(strQdfName).Command
' set pass-through properties
cmd.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
' Update the SQL, or what to select from the query
cmd.CommandText = strSQL
' Update the Connection string, make sure we successfully get through
'your SQL Server
If Not IsMissing(varConnect) Then
cmd.Properties _
( "Jet OLEDB:Pass Through Query Connect String") = CStr(varConnect)
End If
' Update the ReturnsRecords property
' to return or NOT return records
cmd.Properties( _
"Jet OLEDB:Pass Through Query Bulk-Op") = Not fRetRecords 'or fRetRecords
' Save the changes you have fired
Set cat.Procedures(strQdfName).Command = cmd
'Clean up variables
Set cmd = Nothing
Set cat = Nothing
I recognize this...'Microsoft Access Developer's Guide to SQL Server' by Mary Chipman and Andy Baron.
I used the DAO version myself...easier to read.
-
Nov 9th, 2006, 10:33 PM
#5
Thread Starter
Hyperactive Member
Re: PassThrough Query
Yep, text book and well text book doesn't work if you (me) do not know how to maniputlate it correctly.
How do you use/or what do you use with DAO? Currently we are creating a querydef and then running it and it takes 5 minutes to return the dataset. That is way too long for a user to wait. There has to be something better.
This ADO stuff looked better but I do not know how to change it for my purposes.
P.S.
I know how to write a pass thru query it is how do I do it with ADO and have it work, is the question.
Swoozie
Somedays you just should not get out of bed.
-
Nov 10th, 2006, 03:54 AM
#6
Hyperactive Member
Re: PassThrough Query
 Originally Posted by swoozie
Yep, text book and well text book doesn't work if you (me) do not know how to maniputlate it correctly.
How do you use/or what do you use with DAO? Currently we are creating a querydef and then running it and it takes 5 minutes to return the dataset. That is way too long for a user to wait. There has to be something better.
This ADO stuff looked better but I do not know how to change it for my purposes.
P.S.
I know how to write a pass thru query it is how do I do it with ADO and have it work, is the question.
The PassThroughDAO sub itself takes milliseconds to run. Access is slow with native data or data on an external server, though.
This is how we've implemented the DAO sub:
VB Code:
' Adapted from 'Microsoft Access Developer's Guide to SQL Server' by Chipman and Baron
Public Sub PassthroughDAO( _
ByVal strQdfName As String, _
ByVal strSQL As String, _
Optional fRetRecords As Boolean = True)
'Modifies pass-through query properties
'inputs: strQdfName = name of the query
'strSQL = new SQL string
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs(strQdfName)
qdf.ReturnsRecords = fRetRecords
qdf.sql = strSQL
db.QueryDefs.Refresh
End Sub
It's very easy to use. Of course, ADO is the preferred method in Access 2003; we were using Access 97 (we're no longer developing that app) so DAO was much easier to use in our case. I'm afraid I don't really understand that book's ADO method either, which is why I used the DAO method. Also, since pass-through queries are native Access objects DAO was the logical choice though I'm sure there are some here who would disagree with that. MS is trying to get people to switch to ADO so in terms of backward compatibility it would be a good idea to get the ADO version working but this will hold you over while you continue getting to grips with it. I wouldn't recommend it to be part of your permanent solution though. HTH!
-
Nov 10th, 2006, 10:27 AM
#7
Re: PassThrough Query
I don't know if it will help clarify the ADO code you have, but here is Microsofts example:
http://support.microsoft.com/kb/304323
-
Nov 10th, 2006, 03:23 PM
#8
Thread Starter
Hyperactive Member
Re: PassThrough Query
Okay, here is a really stupid question. We have been so hung up here on passthru queries, I didnt even think. Is there a reason we can not just go grab a recordset and return it to a temp table then have the report pull from the temp table? Or is it because we can not use the same query we would use in a passthru for obtaining a recordset?
What would you use if you had to pull specific data into access from Oracle to populate a report?
Swoozie
Somedays you just should not get out of bed.
-
Nov 10th, 2006, 06:53 PM
#9
Hyperactive Member
Re: PassThrough Query
 Originally Posted by swoozie
Okay, here is a really stupid question. We have been so hung up here on passthru queries, I didnt even think. Is there a reason we can not just go grab a recordset and return it to a temp table then have the report pull from the temp table? Or is it because we can not use the same query we would use in a passthru for obtaining a recordset?
What would you use if you had to pull specific data into access from Oracle to populate a report?
We use SQL Server, not Oracle, so I can't really comment on Oracle's capabilities but the object library is the same no matter what DB you use (I think, the others will definitely jump in if I'm wrong). The VB version of our app obviously doesn't have pass-through queries and Access 2003 uses the same dll for its ADO reference. Why not try it out, see how it goes?
We used pass-through queries in the original Access app because I was still finding my way around VB and found it easier to do it that way, but you definitely don't have to do it that way if you don't want to and you can save yourself the overhead of having to modify a native Access object every time you want to retrieve data.
-
Nov 22nd, 2006, 01:43 PM
#10
Thread Starter
Hyperactive Member
Re: PassThrough Query
i would love to try it out but every one is on vacation that "owns" the project. Can't wait until after the holidays.
Swoozie
Somedays you just should not get out of bed.
-
Nov 22nd, 2006, 02:44 PM
#11
Re: PassThrough Query
As far as I know, the EXECUTE method of Connection object executes a Passthrough query.
Things like this work easily.
VB Code:
'' your query
sQuery = "Delete FROM Customer WHERE 0=1" '' whatever your passthrough query
''Then execute the query
cn.Execute sQuery
''incase you expect something returning, get it in a recordset object
sQuery = "SELECT * FROM Customer"
Set rs = cn.Execute(sQuery)
Pradeep
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
|