473,395 Members | 1,870 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,395 software developers and data experts.

VBA datatype mismatch error 13

Hi,

Iam coding data access application with database object and recordset.
Here' s my code
'------------------------------------------------------------------
Private Function CreateRecordSet() As Boolean
Dim db As Database
Dim rs As Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase(txtDBpath)
sql = "SELECT * FROM TblMembers"
Set rs = db.OpenRecordset(sql, dbOpenDynaset) 'THE ERROR
APPEARS HERE
MsgBox "show this", vbOKOnly

If Err.Number = 0 Then
CreateRecordSet = True
MsgBox "no error", vbInformation
Else
CreateRecordSet = False
MsgBox Err.Description, vbCritical
End If
End Function
'------------------------------------------------------------------

I got an error 13 at runtime that says "Type mismatch". I look at different
books and the internet but still convince myself that my code is OK. No
errors were found after OpenDatabase method, and the txtDBpath is correct,
TblMembers is one of the tables in the .mdb file
Can someone tell me why I got that error at runtime.

I am running
windows xp
visual basic 6,
mdb file was create in Access 2003 and converted to Access97

Thanks.


Nov 13 '05 #1
2 13520
It's possible that you have a reference set to both ADO and DAO, and that
the ADO reference is higher in the sequence than DAO.

Try changing your declaration to Dim rs AS DAO.Recordset

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"JingleBEV" <n_****@NOSPAMyahoo.com> wrote in message
news:gP********************@news20.bellglobal.com. ..
Hi,

Iam coding data access application with database object and recordset.
Here' s my code
'------------------------------------------------------------------
Private Function CreateRecordSet() As Boolean
Dim db As Database
Dim rs As Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase(txtDBpath)
sql = "SELECT * FROM TblMembers"
Set rs = db.OpenRecordset(sql, dbOpenDynaset) 'THE ERROR APPEARS HERE
MsgBox "show this", vbOKOnly

If Err.Number = 0 Then
CreateRecordSet = True
MsgBox "no error", vbInformation
Else
CreateRecordSet = False
MsgBox Err.Description, vbCritical
End If
End Function
'------------------------------------------------------------------

I got an error 13 at runtime that says "Type mismatch". I look at different books and the internet but still convince myself that my code is OK. No
errors were found after OpenDatabase method, and the txtDBpath is correct,
TblMembers is one of the tables in the .mdb file
Can someone tell me why I got that error at runtime.

I am running
windows xp
visual basic 6,
mdb file was create in Access 2003 and converted to Access97

Thanks.

Nov 13 '05 #2
Hi.

This is possibly a WAG (Wild-Ass Guess) but is the database defined by
"txtDBPath" also an Access97 .MDB?
If it happens to be a newer version, it will likely be using ADO instead of
DAO by default.

Here are a couple of things to try:
Dim your Database and Recordsets objects explicitly as DAO objects.(Access97
won't mind)
I had also noticed that your code did not declare your "sql" variable as
String data type.
I believe that undeclared variables are treated as Variant, and this may be
where the Error code 13 comes from?

I also renamed "sql" to "MySQL" as SQL may be a reserved word.
Note the semicolon that I added to the end of your SQL string.
Some will say that it's not absolutely required, but I always put it in to
signal the end of the string.

********************************************
Private Function CreateRecordSet() As Boolean

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = DBEngine.Workspaces(0).OpenDatabase(txtDBpath)

Dim MySQL As String
MySQL = "" 'Clear the string variable (by habit)

MySQL = MySQL & "SELECT * FROM TblMembers;"

Set rs = db.OpenRecordset(MySQL, dbOpenDynaset)
MsgBox "show this", vbOKOnly

If Err.Number = 0 Then
CreateRecordSet = True
MsgBox "no error", vbInformation
Else
CreateRecordSet = False
MsgBox Err.Description, vbCritical
End If

End Function
********************************************

--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================


"JingleBEV" <n_****@NOSPAMyahoo.com> wrote in message
news:gP********************@news20.bellglobal.com. ..
Hi,

Iam coding data access application with database object and recordset.
Here' s my code
'------------------------------------------------------------------
Private Function CreateRecordSet() As Boolean
Dim db As Database
Dim rs As Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase(txtDBpath)
sql = "SELECT * FROM TblMembers"
Set rs = db.OpenRecordset(sql, dbOpenDynaset) 'THE ERROR APPEARS HERE
MsgBox "show this", vbOKOnly

If Err.Number = 0 Then
CreateRecordSet = True
MsgBox "no error", vbInformation
Else
CreateRecordSet = False
MsgBox Err.Description, vbCritical
End If
End Function
'------------------------------------------------------------------

I got an error 13 at runtime that says "Type mismatch". I look at different books and the internet but still convince myself that my code is OK. No
errors were found after OpenDatabase method, and the txtDBpath is correct,
TblMembers is one of the tables in the .mdb file
Can someone tell me why I got that error at runtime.

I am running
windows xp
visual basic 6,
mdb file was create in Access 2003 and converted to Access97

Thanks.

Nov 13 '05 #3

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

Similar topics

2
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't...
2
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".&nbsp; Here's an example table that I'm working with... ...
3
by: Savas Ates | last post by:
i have 3 columns in sql server .. all of them are numeric value when a user enter my site i take the value of userid (numeric one) i assign it as session("userid ") after a query i take 2...
11
by: Tom Clavel | last post by:
I need to make sure that I am on a different record than I just was on, in a DAO recordset. code fragment: 1. strFind = "thisSource = " & tripID & " AND thisTrip = " & tripID 2. ...
2
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of...
0
by: Snoopy33 | last post by:
I have a query that builds a date from a text field with the date imput as yyyymmdd in the query, so i have to piece it together in my expression as follows: exp:...
9
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
14
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
12
by: gravesk | last post by:
Hello - I am a novice in MS Access and do not know SQL. I am using Access 2003. I have set up two queries that seem to be working fine. Each comes directly from a table. I have joined the...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.