Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / May 2008

Tip: Looking for answers? Try searching our database.

Form-Entered Parameters for Pass-thru query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chantal A - 14 May 2008 20:37 GMT
I have three pass through queries set up in my Access database that
are processed on a MSSQL server.  All three queries function properly
and process the data as expected.  My problem is that the parameters
(FromDate and ToDate) are being entered via three different forms--one
form for each query.  I would like for one form to execute all three
pass through queries.  How can I make this work?

Here is my code: (basically the same for each form with different
query identified)

Private Sub cmdRunqptRenewalRate_Click()

   Dim db As DAO.Database
   Dim strFromDate As String
   Dim strToDate As String
   Dim qd As DAO.QueryDef
   Dim strSQL As String

   ' Ensure date-string inputs exist.
   ' NOTE: The code requires that both dates
   ' are supplied.

   With Me!txtFromDate
       If IsNull(.Value) Then
           MsgBox "Please specify the first PaidThru date for the
report."
           .SetFocus
           Exit Sub
       Else
           strFromDate = Format(.Value, "YYYY-MM-DD")
       End If
   End With

   With Me!txtToDate
       If IsNull(.Value) Then
           MsgBox "Please specify the last PaidThru date for the
report."
           .SetFocus
           Exit Sub
       Else
           strToDate = Format(.Value, "YYYY-MM-DD")
       End If
   End With

   ' Build the SQL query.
   strSQL = _
       "exec  sp_NBAA_RenewRate '" & strFromDate & _
       "','" & strToDate & "'"

   Set db = CurrentDb()
   Set qd = CurrentDb.QueryDefs("qry_update1_UD_Renewals")
       qd.SQL = strSQL
       qd.Connect =
"ODBC;DSN=IMIS_NBAA_Prod;Database=DB_name;Uid=XXX;Pwd=****;"
              qd.ODBCTimeout = 300
       qd.ReturnsRecords = False

   DoCmd.OpenQuery "qry_update1_UD_Renewals"
   'DoCmd.RunSQL strSQL
Douglas J. Steele - 14 May 2008 21:48 GMT
You have to repeat

  Set qd = CurrentDb.QueryDefs("qry_update1_UD_Renewals")
       qd.SQL = strSQL
       qd.Connect =
"ODBC;DSN=IMIS_NBAA_Prod;Database=DB_name;Uid=XXX;Pwd=****;"
              qd.ODBCTimeout = 300
       qd.ReturnsRecords = False

   DoCmd.OpenQuery "qry_update1_UD_Renewals"

for each of the queries.

Note that you'd likely be better off using

   qd.Execute dbFailOnError

rather than

   DoCmd.OpenQuery "qry_update1_UD_Renewals"

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

>I have three pass through queries set up in my Access database that
> are processed on a MSSQL server.  All three queries function properly
[quoted text clipped - 55 lines]
>    DoCmd.OpenQuery "qry_update1_UD_Renewals"
>    'DoCmd.RunSQL strSQL
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.