N
nxqviet
Hi all,
I have this SQL code that will Append some record from one table to
another, from tblPrices to a table with a name defined by the SessionID
of the user "varName ". This "varName " will also be the criteria of
the append query. This code does not work for some reason, saying that
the syntax is error. Can some one help please.
Thank.
=================CODE Begin===============
'Append prices from temp table to New editing table
Dim varName As Variant
varName = SessionID.Value
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryAppendEdit")
' Define Criteria
strCriteria = strCriteria & "tblPrices.SessionID = " & Chr(34) &
varName
' Build the new SQL statement incorporating the string
strSQL = "INSERT INTO " & varName & "(ServiceID, ServiceName, Price) "
& _
"SELECT tblPrices.ServiceID, tblPrices.ServiceName, tblPrices.Price
FROM tblPrices" & _
"WHERE " & strCriteria
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryAppendEdit"
DoCmd.SetWarnings True
==========End Code==================
I have this SQL code that will Append some record from one table to
another, from tblPrices to a table with a name defined by the SessionID
of the user "varName ". This "varName " will also be the criteria of
the append query. This code does not work for some reason, saying that
the syntax is error. Can some one help please.
Thank.
=================CODE Begin===============
'Append prices from temp table to New editing table
Dim varName As Variant
varName = SessionID.Value
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryAppendEdit")
' Define Criteria
strCriteria = strCriteria & "tblPrices.SessionID = " & Chr(34) &
varName
' Build the new SQL statement incorporating the string
strSQL = "INSERT INTO " & varName & "(ServiceID, ServiceName, Price) "
& _
"SELECT tblPrices.ServiceID, tblPrices.ServiceName, tblPrices.Price
FROM tblPrices" & _
"WHERE " & strCriteria
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryAppendEdit"
DoCmd.SetWarnings True
==========End Code==================