I'm trying to collect some data from a database using VBA code
I have the following
I have 2 variables (VIN_T
& PN5D_T
) and I want to return he RO_Num
, for that, I have to use as a filter the 2 variables on my database. I have declared:
strQuery = "SELECT [RONum] FROM [dbo].[Warranty] WHERE RIGHT([VIN],6)=VIN_T AND LEFT([PN],5)=PN5D_T"
However, I get an error: Run-time error '-2147217900 (80040e14) Invalid column name 'VIN_T'
, I have tested the same query code with the direct value and the code works
strQuery = "SELECT [RONum] FROM [dbo].[Warranty] WHERE RIGHT([VIN],6)='470765' AND LEFT([PN],5)='27301'"
I have declared both variables as:
Dim VIN_T As String
Dim PN5D_T As String
So i don´t understand why I'm getting this error, therefore, I would like to know, how can I pass the 2 variables on my strQuery
?
Thanks in advance