pass through query with parameters

mshellay

New member
Local time
Today, 17:52
Joined
Dec 30, 2014
Messages
7
I have been scouring the internet trying to find a solution for my issue, to no avail. This is my first time writing a pass through query pinging sql tables using an input parameter from a form. I have gotten as far as executing the query but I can't seem to display the result to ensure it's pulling the right records. I also want to be able to append the records to a table. Can anyone help with these two things? This my first time using querydefs and pass throughs so I am a little sketchy on how it works. Below is the code I have written so far:

Sub GETRT()

Code:
Dim db As DAO.Database
Dim QDF As QueryDef
Dim STRSQL As String
Dim RS As Recordset

STRSQL = "SELECT * FROM LAB_MESR.ODM_RT_DAYS" & _
"WHERE LOCATION_ID=" & [Forms]![PARMS]![STR_NBR]


Set db = CurrentDb
Set QDF = db.QueryDefs("001:GET_LT")
 QDF.SQL = STRSQL


End Sub
 
I tired docmd and now I'm getting syntax error on location_id. It highlights the docmd line when I debug. I attached a screenshot of the error. thoughts?
 

Attachments

  • error.jpg
    error.jpg
    95.6 KB · Views: 963
You know what I'm so silly. I figured out why I got the error. I forgot to take out the "where" statement in my pass through query. It's so late!! Anyway your solution worked. How can I append this data to a table?
 
make your code readable to prevent such things, this DOES include SQL :)
Code:
STRSQL = " SELECT * " & _
         " FROM   LAB_MESR.ODM_RT_DAYS " & _
         " WHERE  LOCATION_ID= " & [Forms]![PARMS]![STR_NBR]
 
How can I append this data to a table?

Why would you want to duplicate the data? That generaly is a bad idea...

Assuming you mean a table inside the access database:
You can simply have a normal append query and use this ODBC query as its source.
Currentdb.execute "appendquery"

Assuming you want it in the ODBC database.
run an insert into query as an action query.
QDF.Execute
 

Users who are viewing this thread

Back
Top Bottom