473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why do I get a type mismatch error (13)?

I have a form with the following code on Click that calls a procedure passing a
date data type value. The field in the table is a date/time data type.
What is causing the type mismatch when it reaches the line (Set rstVehID =
dbsVehID.OpenRecordset())? GStartDate and GEndDate are declared as public
variables. Thanks.

Private Sub cmdSelectSTDate_Click()
Dim datDateSelected As Date

cboSTDATERange.SetFocus
If IsNull(cboSTDATERange) = False Then
datDateSelected = cboSTDATERange.Value
Call ProcGetVehID(datDateSelected)
Else
MsgBox ("Please select a Date from the Drop Box, then click the [Select
Date] button")
cboSTDATERange.SetFocus
End If

End Sub
Private Sub ProcGetVehID(ByVal datDateSelected As Date)
'Dim strEndDate As String
Dim dbsVehID As Database
Dim qdfVehID As QueryDef
Dim rstVehID As Recordset
'Dim fld As Field
Dim sqlVehID As String

If datDateSelected = Null Then
GoTo err_ProcGetVehID
End If

If IsNull(datDateSelected) = False Then
GStartDate = datDateSelected
GEndDate = DateAdd("d", 6, datDateSelected)

Set dbsVehID = CurrentDb
Set qdfVehID = dbsVehID.QueryDefs("qryGetVehID")
qdfVehID.SQL = "SELECT VehicleID FROM ChargeLog WHERE STDATE BETWEEN #"
& GStartDate & "# AND " & "#" & GEndDate & "#"
Set rstVehID = dbsVehID.OpenRecordset()
End If

If Not rstVehID.EOF Or Not rstVehID.BOF Then
cboVehicleID.SetFocus
'cboVehicleID.Visible
'cboVehicleID.RowSource = rstVehID
cboVehicleID = rstVehID
Else
Exit Sub
End If

rstVehID.Close
dbsVehID.Close
Set rstVehID = Nothing
Set dbsVehID = Nothing

err_ProcGetVehID:
Exit Sub
end sub

Nov 12 '05 #1
2 19286
> Set qdfVehID = dbsVehID.QueryDefs("qryGetVehID")
qdfVehID.SQL = "SELECT VehicleID FROM ChargeLog WHERE STDATE BETWEEN #"
& GStartDate & "# AND " & "#" & GEndDate & "#"
Set rstVehID = dbsVehID.OpenRecordset()


Use instead:
Set rstVehID = dbsVehID.OpenRecordset(qdfVehID.SQL, dbOpenDynaset)

But you can easier fill a string ...

strSelect = "SELECT VehicleID FROM ChargeLog WHERE STDATE BETWEEN #"
& GStartDate & "# AND " & "#" & GEndDate & "#;"

.... and open it:

Set rstVehID = dbsVehID.OpenRecordset(strSelect, dbOpenDynaset)

Then you can get rid of the QueryDef which you're not using otherwise.

HTH - Peter

--
No mails please.
Nov 12 '05 #2
What version of Access? If you're using Access 2000 or 2002, when you added
the reference to DAO, did you remove the reference to ADO?

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rstVehID as DAO.Recordset (to guarantee an ADO recordset, you'd use
Dim rstVehID As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"mark" <ms@nospam.comcast.net> wrote in message
news:3v********************@comcast.com...
I have a form with the following code on Click that calls a procedure passing a date data type value. The field in the table is a date/time data type.
What is causing the type mismatch when it reaches the line (Set rstVehID =
dbsVehID.OpenRecordset())? GStartDate and GEndDate are declared as public
variables. Thanks.

Private Sub cmdSelectSTDate_Click()
Dim datDateSelected As Date

cboSTDATERange.SetFocus
If IsNull(cboSTDATERange) = False Then
datDateSelected = cboSTDATERange.Value
Call ProcGetVehID(datDateSelected)
Else
MsgBox ("Please select a Date from the Drop Box, then click the [Select Date] button")
cboSTDATERange.SetFocus
End If

End Sub
Private Sub ProcGetVehID(ByVal datDateSelected As Date)
'Dim strEndDate As String
Dim dbsVehID As Database
Dim qdfVehID As QueryDef
Dim rstVehID As Recordset
'Dim fld As Field
Dim sqlVehID As String

If datDateSelected = Null Then
GoTo err_ProcGetVehID
End If

If IsNull(datDateSelected) = False Then
GStartDate = datDateSelected
GEndDate = DateAdd("d", 6, datDateSelected)

Set dbsVehID = CurrentDb
Set qdfVehID = dbsVehID.QueryDefs("qryGetVehID")
qdfVehID.SQL = "SELECT VehicleID FROM ChargeLog WHERE STDATE BETWEEN #" & GStartDate & "# AND " & "#" & GEndDate & "#"
Set rstVehID = dbsVehID.OpenRecordset()
End If

If Not rstVehID.EOF Or Not rstVehID.BOF Then
cboVehicleID.SetFocus
'cboVehicleID.Visible
'cboVehicleID.RowSource = rstVehID
cboVehicleID = rstVehID
Else
Exit Sub
End If

rstVehID.Close
dbsVehID.Close
Set rstVehID = Nothing
Set dbsVehID = Nothing

err_ProcGetVehID:
Exit Sub
end sub

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
5
by: Chris | last post by:
Hi everyone, I have an error message in an Access 97 database & I was hoping someone may be able to help me get rid of it (bearing in mind I only have an average understanding of Access &...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
1
by: jmarr02s | last post by:
I am using MS Access 2003 and get the following error "Data type mismatch in criteria expression" Any suggestions on how to fix this? This is my code: SELECT IIf(=15 Or =19, "15 og 19",...
6
by: christianlott1 | last post by:
Taken (and modded) from http://www.codeguru.com/vb/gen/vb_misc/tips/ article.php/c13137 'RESULTS' table: REF_STRING - TEXT 250 TEST_STRING - TEXT 250 MATCH_VALU - SINGLE FIXED 2 DECIMAL...
2
by: mujaqo | last post by:
I have a table consist of two fields UserID and Password, and a form with unbounded fields txtUserID and txtPassword. I’m running the below code on MS Access 2000 and I’m getting Run-time error...
2
by: skundu | last post by:
Hi, I have just joined. I am getting a message when I am running a macro - run time error '13', type mismatch. when I am debuggung it it opens up my VBA code and shows this: Sub Updategraph()...
10
by: jasperz01 | last post by:
Hello, I'm kind of new to VBA and Access, so please forgive me if I'm doing stuff all wrong: I have the following code wich gives me a Error 13 Type Mismatch: Dim db As Database, rs...
2
by: tiiim | last post by:
hi all i created two textboxes to insert date and a button..i hv this following code for that button..but when i ran error msg shows error like 'runtime error 13' & type mismatch..i hv no idea...
1
by: Greg (codepug | last post by:
Solution Note: I am experimenting with an excellent popup calendar I found on the Allen Browne web site. I was receiving the following error (Error 13: Type mismatch) when clicking a button...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.