troubleshooting Question

Variable in SQL Statement

Avatar of RichFrot
RichFrotFlag for United States of America asked on
Visual Basic ClassicSQL
4 Comments1 Solution357 ViewsLast Modified:
Using VB 6, trying to pass a variable to a SQL Statement.  Recieve the following error message.  " Data type mismatch in criteria expression".  The problem is in the Where Statement using the variable txtClientNo.

Current Code:
Dim txtClientNo As String
txtClientNo = Mid(sText, 34, 4)

SQLQuery2 = "Select tblSysCompanyAvail.CompanyCode, tblSysCompanyAvail.CompanyName, tblSysCompanyAvail.EmployerIDNum, tblSysCompanyAvail.Address1, tblSysCompanyAvail.City, tblSysCompanyAvail.State, tblSysCompanyAvail.ZipCode " _
& "FROM tblSysCompanyAvail " _
& "WHERE tblSysCompanyAvail.CompanyCode = " & txtClientNo & "; "
rst2.Open SQLQuery2, cnn2, adOpenKeyset, adLockOptimistic

When I change " & txtClientNo & " to '1345' an actual value the code works.  The CompanyCode database field is a text field.
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros