Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • Last Modified:

Access VB select statement

I am trying to write a select statement in vb for access, but whenever I open the recordset it gives a data type mismatch error.

Dim rTestCells As Recordset
Dim strSQL2 As String
Dim iSolId As Variant

strSQL2 = "SELECT utcid FROM tbl_Temp_Import WHERE upcid = " & iSolId
Set rTestCells = dbs.OpenRecordset(strSQL2)

I'm running a loop from another recordset that populates the iSolId variable that works fine, but this select statement bombs out whenever the Where clause is added.

Any ideas?
1 Solution
if the upcid field is text then use

strSQL2 = "SELECT utcid FROM tbl_Temp_Import WHERE upcid = " & Chr(34) & iSolId & Chr(34)

the Chr(34)'s put in " around your text.

Cheers, Andrew
I will say like TestReport this is probably because this is a text field.  You can also use this synthaxe

"SELECT utcid FROM tbl_Temp_Import WHERE upcid = '" & iSolId & "'"
JaiTraiAuthor Commented:
thanks for the information it works great now.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now