Using a stored variable in an SQL select query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoppini
    New Member
    • Jun 2010
    • 8

    Using a stored variable in an SQL select query

    I am trying to use string variables LIN and Portfolio defined from a recordset recControl in VBA SQL Select Query in Microsoft Access 2003. My syntax must be wrong as I keep getting a Syntax error. Can someone help?

    Code:
    LIN = recControl!LIN_Number
    Portfolio = recControl!Portfolio_Name
    
    Dim mySQL5 As String
    mySQL5 = "SELECT TempAPT.*, TransactionTypes.TranType"
    mySQL5 = mySQL5 + " FROM TempAPT INNER JOIN TransactionTypes ON"
    mySQL5 = mySQL5 + " TempAPT.TranAsset_Name = TransactionTypes.TranAsset_Name"
    mySQL5 = mySQL5 + " WHERE TempAPT.LIN_Number = " & LIN & ""
    mySQL5 = mySQL5 + " AND TempAPT.Portfolio_Name = " & Portfolio & ""
    
    Set recRecords = db.OpenRecordset(mySQL5, dbOpenDynaset)
Working...