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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

ADO recordsource syntax

Attempting to do a SQL query to an Access DB using the ADO control
getting a type mismatch.

Private Sub cmdSearch_Click()
frmCMS.Adodc1.RecordSource = _
    "select * from tblTable where IDNum = '" & txtIDSrch.Text
frmCMS.Adodc1.Refresh
End Sub
where txtIDSrch is a TextBox

If I enter 1014 in the texbox
get the error

Syntax error in query expression 'IDNum='1014'  

I'm sure that this is a simple thing on my part, but Im kind of new at this string within a string thing
0
jackassplus
Asked:
jackassplus
1 Solution
 
hongjunCommented:
Try this if IDNum is a string field
frmCMS.Adodc1.RecordSource = _
"select * from tblTable where IDNum = '" & txtIDSrch.Text & "'"


Try this if IDNum is an integer field
frmCMS.Adodc1.RecordSource = _
"select * from tblTable where IDNum = " & txtIDSrch.Text


hongjun
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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