2 Replies - 3113 Views - Last Post: 23 March 2009 - 01:01 AM Rate Topic: -----

#1 svntn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-March 09

data type mismatch in criteria expression

Posted 22 March 2009 - 08:55 AM

Hi! I am doing a simpe database here. I am making a find function wherein you will type the item name in the input box. It works properly but when i click find an error message comes up saying "data type mismatch in criteria expression"

my database has only one field which is item name. it's a string..

here is my code

Private Sub mnuFind_Click()
stock = InputBox("Enter Item Name", "Find")
	If stock <> "" Then
		SearchString = "itemname=" & Val(stock)
		Data1.Recordset.FindFirst SearchString
		If Data1.Recordset.NoMatch = True Then
			MsgBox "No Matching Record", 0, "Find"
		End If
	End If
End Sub



hope you could help me..

thanx!

Is This A Good Question/Topic? 0
  • +

Replies To: data type mismatch in criteria expression

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: data type mismatch in criteria expression

Posted 22 March 2009 - 09:01 AM

Put single quotes around the value since it's a string. The way you have it now the DB is expecting a numeric value. Try this modification

SearchString = "itemname='" & Val(stock) & "'"



That should help :)
Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: data type mismatch in criteria expression

Posted 23 March 2009 - 01:01 AM

As you step through the code and know that your string variable "stock" has a value, goto the immediate window and type in...
?Val(stock)


or just active the immediat window (if not active) by pressing CTRL+G and type in...
?val("test")


You should receive a...
 0 


I base this post on...

Quote

Hi! I am doing a simpe database here. I am making a find function wherein you will type the item name in the input box. ... my database has only one field which is item name. it's a string..

To me "item name" is descriptive like computer or hard drive 80Gb but if you ARE inputting numbers, well then...

what if the item name is '0001'
?val("0001")
 1 



Now, if I am coming from left field then...

[said in meek voice]Nevermind, I'll be quiet now...[end meek voice]

Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1