[AccessD] Feed variable to parameter query

Kaup, Chester Chester_Kaup at kindermorgan.com
Thu Jul 28 08:24:37 CDT 2005


I am trying to feed a variable into a parameter query. I have done this
with dates but cannot get the syntax right (correct combination of
single, double quotes etc.) on pushing this text field into the query.
If someone has a better way to push a variable into a parameter query
feel free to jump in. Thanks all. Below is the code.

 

Option Compare Database

 

Function Table_Data_to_Parameter_Query()

 

    Dim MyDb As Database, MyQDef As QueryDef, myds As Recordset, myds1
As Recordset

    Dim strSQL As String, Table_Data As String

    

    Set MyDb = CurrentDb()

    Set myds = MyDb.OpenRecordset("tbl Patterns to Run", dbOpenTable)

    Set MyQDef2 = MyDb.QueryDefs("qry Pattern Start Date")

    

    PatternName = myds.Fields(0)

 

    strSQL = "SELECT Pattern, [CO2 Injection Start Date Schedule1]" & _

    "FROM [tbl Schedules]" & _

    "WHERE [tbl Schedules].Pattern=PatternName;"

 

    Set MyQDef = MyDb.QueryDefs("qry Pattern Start Date")

    MyQDef.SQL = strSQL

    Set myds1 = MyQDef.OpenRecordset()

    Table_Data = myds1.Fields(0)

    

    Set MyQDef = Nothing

 

 

Chester Kaup

Engineering Technician

Kinder Morgan CO2 Company, LLP

Office (432) 688-3797

 

No trees were killed in the sending of this message. However a large
number of electrons were terribly inconvenienced.

FAX (432) 688-3799

 




More information about the AccessD mailing list