944,116 Members | Top Members by Rank

Ad:
Sep 20th, 2006
0

error on refresh

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
stan yost is offline Offline
29 posts
since Aug 2006
Sep 20th, 2006
0

Re: error on refresh

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Sep 23rd, 2006
0

Re: error on refresh

Click to Expand / Collapse  Quote originally posted by Comatose ...
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?
Reputation Points: 10
Solved Threads: 0
Light Poster
stan yost is offline Offline
29 posts
since Aug 2006
Sep 25th, 2006
1

Re: error on refresh

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.
Reputation Points: 20
Solved Threads: 10
Junior Poster
aparnesh is offline Offline
193 posts
since Jul 2005
Sep 25th, 2006
0

Re: error on refresh

Thank you very much!
Reputation Points: 10
Solved Threads: 0
Light Poster
stan yost is offline Offline
29 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Problem in Serial Communication In Visual Basic
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB/word 2000/template forms





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC