Results 1 to 11 of 11

Thread: PassThrough Query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    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:
    1. Public Sub PassThroughADO(ByVal strQdfName As String, _
    2.                                       ByVal strSQL As String, _
    3.                                       Optional varConnect As Variant, _
    4.                                       Optional fRetRecords As Boolean = True)
    5.  
    6.     '   strQdfName is the name of the query
    7.     '   strSQL  is the new SQL string, if you need to update the original query
    8.     '   varConnect is the optional connection string, probably need this
    9.     '   fRetRecords Optional returns records defaults to True(or yes, what you want)
    10.  
    11.     Dim cat As ADOX.Catalog
    12.     Dim cmd As ADODB.Command
    13.  
    14.     ' Open the catalog
    15.     Set cat = New ADOX.Catalog
    16.     Set cat.ActiveConnection = cn
    17.  
    18.        ' Get the command to fire
    19.        'here the string parameter of the query name is passed
    20.        
    21.        Set cmd = cat.Procedures(strQdfName).Command
    22.      
    23.       ' set pass-through properties
    24.      
    25.       cmd.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
    26.      
    27.       ' Update the SQL, or what to select from the query
    28.        cmd.CommandText = strSQL
    29.  
    30.           ' Update the Connection string, make sure we successfully get through
    31.           'your SQL Server
    32.          If Not IsMissing(varConnect) Then
    33.             cmd.Properties _
    34.             ( "Jet OLEDB:Pass Through Query Connect String") = CStr(varConnect)
    35.          End If
    36.    
    37.           ' Update the ReturnsRecords property
    38.           ' to return or NOT return records
    39.  
    40.         cmd.Properties( _
    41.        "Jet OLEDB:Pass Through Query Bulk-Op") = Not fRetRecords 'or fRetRecords
    42.  
    43.      ' Save the changes you have fired
    44.  
    45.       Set cat.Procedures(strQdfName).Command = cmd
    46.      
    47.      'Clean up variables
    48.      Set cmd = Nothing
    49.      Set cat = Nothing
    Swoozie
    Somedays you just should not get out of bed.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    Re: PassThrough Query

    Good morning! Is there anyone familiar with this topic?
    Swoozie
    Somedays you just should not get out of bed.

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: PassThrough Query

    Quote 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."


  4. #4
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: PassThrough Query

    Quote 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:
    1. Public Sub PassThroughADO(ByVal strQdfName As String, _
    2.                                       ByVal strSQL As String, _
    3.                                       Optional varConnect As Variant, _
    4.                                       Optional fRetRecords As Boolean = True)
    5.  
    6.     '   strQdfName is the name of the query
    7.     '   strSQL  is the new SQL string, if you need to update the original query
    8.     '   varConnect is the optional connection string, probably need this
    9.     '   fRetRecords Optional returns records defaults to True(or yes, what you want)
    10.  
    11.     Dim cat As ADOX.Catalog
    12.     Dim cmd As ADODB.Command
    13.  
    14.     ' Open the catalog
    15.     Set cat = New ADOX.Catalog
    16.     Set cat.ActiveConnection = cn
    17.  
    18.        ' Get the command to fire
    19.        'here the string parameter of the query name is passed
    20.        
    21.        Set cmd = cat.Procedures(strQdfName).Command
    22.      
    23.       ' set pass-through properties
    24.      
    25.       cmd.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
    26.      
    27.       ' Update the SQL, or what to select from the query
    28.        cmd.CommandText = strSQL
    29.  
    30.           ' Update the Connection string, make sure we successfully get through
    31.           'your SQL Server
    32.          If Not IsMissing(varConnect) Then
    33.             cmd.Properties _
    34.             ( "Jet OLEDB:Pass Through Query Connect String") = CStr(varConnect)
    35.          End If
    36.    
    37.           ' Update the ReturnsRecords property
    38.           ' to return or NOT return records
    39.  
    40.         cmd.Properties( _
    41.        "Jet OLEDB:Pass Through Query Bulk-Op") = Not fRetRecords 'or fRetRecords
    42.  
    43.      ' Save the changes you have fired
    44.  
    45.       Set cat.Procedures(strQdfName).Command = cmd
    46.      
    47.      'Clean up variables
    48.      Set cmd = Nothing
    49.      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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    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.

  6. #6
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: PassThrough Query

    Quote 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:
    1. ' Adapted from 'Microsoft Access Developer's Guide to SQL Server' by Chipman and Baron
    2. Public Sub PassthroughDAO( _
    3.     ByVal strQdfName As String, _
    4.     ByVal strSQL As String, _
    5.     Optional fRetRecords As Boolean = True)
    6.    
    7.     'Modifies pass-through query properties
    8.     'inputs: strQdfName = name of the query
    9.     'strSQL = new SQL string
    10.    
    11.     Dim db As DAO.Database
    12.     Dim qdf As DAO.QueryDef
    13.    
    14.     Set db = CurrentDb
    15.     Set qdf = db.QueryDefs(strQdfName)
    16.    
    17.     qdf.ReturnsRecords = fRetRecords
    18.     qdf.sql = strSQL
    19.     db.QueryDefs.Refresh
    20.  
    21. 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!

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    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.

  9. #9
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: PassThrough Query

    Quote 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.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    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.

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Wink 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:
    1. '' your query
    2. sQuery = "Delete FROM Customer WHERE 0=1"     '' whatever your passthrough query
    3.  
    4. ''Then execute the query
    5. cn.Execute sQuery
    6.  
    7.  
    8. ''incase you expect something returning, get it in a recordset object
    9. sQuery = "SELECT * FROM Customer"
    10. Set rs = cn.Execute(sQuery)

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width