Variables in SQL string statements. (1 Viewer)

Clepto

Registered User.
Local time
Today, 03:53
Joined
May 12, 2012
Messages
35
I have been struggling with this all morning, and it has got me stumped.
I have established the variable “var” and I wish to use it to replace the integer “7” at the end the following SQL statement, which is contained in a string and works as it is. However I wish to vary this integer value in the finished module
I understand that the use of quotation marks in SQL string statements is complex. I have tried various solutions I have found on the net, but they do not work. Is the parenthesis causing an added complication? :banghead:


Dim var As Integer
var = 7

‘Later in the module I have:

dbs.Execute "INSERT INTO [HeaderT] ( CardBarcode, Kiosk, KioskID )" _
& "SELECT [FixtureOrdersQ].[CardBarcode], [FixtureOrdersQ].[Kiosk], [FixtureOrdersQ].[KioskID]" _
& "FROM [FixtureOrdersQ]" _
& "GROUP BY [FixtureOrdersQ].[CardBarcode], [FixtureOrdersQ].[Kiosk], [FixtureOrdersQ].[KioskID]," _
& "[FixtureOrdersQ].[FixtureID] " _
& "HAVING ((([FixtureOrdersQ].[FixtureID])= 7));"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:53
Joined
Feb 19, 2013
Messages
16,607
you would change the last line to

& "HAVING ((([FixtureOrdersQ].[FixtureID])=" & var & "));"

Note the above is for a numeric value, if it was text it would have additional single quotes e.g.

& "HAVING ((([FixtureOrdersQ].[FixtureID])='" & var & "'));"

note also your code appears to be missing some spaces - particularly before the SELCT, FROM and GROUP BY, tho' this may be due to the system dropping them
 

Clepto

Registered User.
Local time
Today, 03:53
Joined
May 12, 2012
Messages
35
Brilliant! I must have been a character out a number of times.
Thank you so much.
 

Users who are viewing this thread

Top Bottom