error on refresh

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2006
Posts: 29
Reputation: stan yost is an unknown quantity at this point 
Solved Threads: 0
stan yost stan yost is offline Offline
Light Poster

error on refresh

 
0
  #1
Sep 20th, 2006
I am trying to refresh a data control but I keep getting the following message no matter what I try:
Run-time error 3464
Data type mismatch in criteria expression.
If I leave the where clause out I don't get the error message.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdseektask_Click()
  2. Dim strsql As String, temp As Long
  3. Let temp = InputBox("enter a bidnumber:")
  4. Let strsql = "SELECT * from bids where bidno ='" & temp & "'"
  5. Let datbids.RecordSource = strsql
  6. datbids.Refresh
  7.  
  8. End Sub

Please help.
Last edited by Comatose; Sep 20th, 2006 at 10:23 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: error on refresh

 
0
  #2
Sep 20th, 2006
Let strsql = "SELECT * from bids where bidno ='" & temp & "'" is not the solution, try something like:
strsql = "SELECT * from bids where bidno = " & chr(34) & chr(34) & temp & chr(34) & "'" & chr(34)

EDIT: Nevermind, I totally missed the mark on that one! :eek: try something like this (I don't know what bidno is supposed to be, either an integer, or a long, or a double, or what):
Let strsql = "SELECT * from bids where bidno ='" & cint(temp) & "'"
Last edited by Comatose; Sep 20th, 2006 at 10:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 29
Reputation: stan yost is an unknown quantity at this point 
Solved Threads: 0
stan yost stan yost is offline Offline
Light Poster

Re: error on refresh

 
0
  #3
Sep 23rd, 2006
Originally Posted by Comatose View Post
Let strsql = "SELECT * from bids where bidno ='" & temp & "'" is not the solution, try something like:
strsql = "SELECT * from bids where bidno = " & chr(34) & chr(34) & temp & chr(34) & "'" & chr(34)

EDIT: Nevermind, I totally missed the mark on that one! :eek: try something like this (I don't know what bidno is supposed to be, either an integer, or a long, or a double, or what):
Let strsql = "SELECT * from bids where bidno ='" & cint(temp) & "'"
Comatose - In order to simplify things as much as possible I created a new folder on my C drive named testdatabase in which I put a database created in Access named db3. This contains a table named bidtest that has 2 fields, bidnumber and bidtask. Bidnumber is autonumber and bidtask is text. I put a few records in the table and then created a form in VB 5.0 that has a datacontrol named dattestbids and pointed it to the db3 database and the bidtest table as the recordsource. The form also has a text box that points to the table and field bidtask. I have a command button that executes the following sub:

[Private Sub cmdscroll_click()
Set dbsbidinfo = OpenDatabase("c:\testdatabase\db3.mdb")
Set rstbidinfo = _
dbsbidinfo.OpenRecordset("bidtest", dbOpenDynaset)


Dim strsql As String

' Let strsql = "select * from bidtest"
Let strsql = "SELECT * from bidtest where bidnumber ='" & CInt(temp) & "'"
Let dattestbids.RecordSource = strsql
dattestbids.Refresh
End Sub]

The code works until I put in the where clause. When I put the where clause in I get the message : "data type mismatch in criteria expression"
Can you help me with this?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 188
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: error on refresh

 
1
  #4
Sep 25th, 2006
Remove the Single Quotes from the criteria expression. It should be

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Let strsql = "SELECT * from bidtest where bidnumber = " & CInt(temp)

Single Quotes are used for String & Date Datatypes, Not Numbers. Also since you have declared temp as a Long, u shouldn't use CInt. For safety sake, u can use

temp = val(InputBox("...."))

Also you should check if the user has input a number by using IsNumeric Function.
Last edited by aparnesh; Sep 25th, 2006 at 3:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 29
Reputation: stan yost is an unknown quantity at this point 
Solved Threads: 0
stan yost stan yost is offline Offline
Light Poster

Re: error on refresh

 
0
  #5
Sep 25th, 2006
Thank you very much!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 1958 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC