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: 233
  • Last Modified:

Data Type Mismatch in criteria expression!!!

hello,

   I have written a code in VB that should do a query in Microsoft Access
   and show the result in my labels in my forms.

   the code is here:

      Dim table_name as String
      Dim sql as String
      table_name = db.TableDefs(1).Name
      sql = "select * from wholestuff where codestuff=" & table_name
      Set rs = db.OpenRecordset(sql, dbOpenDynaset)
      Label1.Caption = rs("namestuff").value

   in which namestuff is the name of one of the col in wholestuff table
   and codestuff is the name of one of the col in table_name table that
   it paly the role of primary key in this table and it's type is Text.

    but in running this code I get this error:
        "Data Type Mismatch in criteria expression"
         
    why???

        with regards
0
marycore
Asked:
marycore
1 Solution
 
saurabhguptaCommented:
Use,
sql = "select * from wholestuff where codestuff='" & table_name & "'"

If table_name is a string you need 's around it.

Regards
Saurabh
0
 
supunrCommented:
Dim table_name as String
     Dim sql as String
     table_name = db.TableDefs(1).Name
     sql = "select * from wholestuff where codestuff=""" & table_name & """" ' <- need double quotes around string values
     Set rs = db.OpenRecordset(sql, dbOpenDynaset)
     Label1.Caption = "" & rs("namestuff").value

' "" & - in case rs("namestuff").value is null

Good Luck!
0
 
CleanupPingCommented:
Hi marycore,
This old question (QID 20553015) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept supunr's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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