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

Runtime Error '13'

I have an Access DB that was originally created in Access 2, then converted to Access '97, and a few years ago converted again, to Access '03.

During the convert to '03 it was determined that DAO reference was incorrect and needed to be updated to 3.6 which we did.

I have a macro that won't run in '03 but will run under '97

When running the macro, the Error generated is
"Run TIme Error '13' Type mismatch"

Expand|Select|Wrap|Line Numbers
  1. Function Have_Recs(Table_Name As String)
  2.  
  3. ' This function will determine if a table is present and if present
  4. ' does it contain any records
  5. ' Returns -1 if records are found
  6. ' Returns 0 if the table is not present or is present without records
  7.  
  8. Dim listset As Recordset
  9.  
  10. Open_Data_Database
  11. Set listset = db.TableDefs()[/b] (this line is highlited in VBA)
  12.  
  13. Have_Recs = 0
  14. Have_Table = 0
  15.  
  16. listset.MoveFirst
  17.  
  18. While (Not listset.EOF And Have_Table = 0)
  19.    If listset!Name = Table_Name Then
  20.       If (listset!RecordCount > 0) Then
  21.          Have_Recs = -1
  22.       End If
  23.       j = listset!RecordCount
  24.       Have_Table = -1
  25.    End If
  26.    listset.MoveNext
  27. Wend
  28.  
  29. End Function
Does anyone have a clue what I need to do with this?
Apr 29 '10 #1
10 4561
ADezii
8,834 Expert 8TB
@Frabker3
It was easier just to rewrite the code to something simpler and more efficient. The following Function will return True only if a Table exists AND contains at least 1 Record in it:
Expand|Select|Wrap|Line Numbers
  1. Public Function Have_Recs(strTableName As String) As Boolean
  2. If strTableName = "" Then Exit Function
  3.  
  4. Dim tdf As TableDef
  5.  
  6. Have_Recs = False           'Initialize to False
  7.  
  8. For Each tdf In CurrentDb.TableDefs
  9.   If tdf.Name = strTableName Then           'Table exists
  10.     If DCount("*", strTableName) > 0 Then   'Exists and has Records, return True!
  11.       Have_Recs = True
  12.         Exit For
  13.     End If
  14.   End If
  15. Next
  16. End Function
Apr 29 '10 #2
NeoPa
32,556 Expert Mod 16PB
Can you say which line of your code generated the error message?

Welcome to Bytes!
Apr 30 '10 #3
Line 11 of the original post is the offending line. But like everything in programming could be elsewhere as well.
Apr 30 '10 #4
@ADezii
Thank You, this works well. And does what the other was supposed to do.

One issue that came up after this fix was run is that when closing the DB Access stays open. Any ideas?
Apr 30 '10 #5
ADezii
8,834 Expert 8TB
@Frabker3
Hard to say, but sounds like you have a
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.Close 
instead of a
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Quit 
somewhere.
Apr 30 '10 #6
NeoPa
32,556 Expert Mod 16PB
In your original line #11 you are trying to assign a collection of recordsets (No indexd provided) to a recordset object variable. This is not possible. If you were to add an index however, this would be fine. It can also be done within a looping structure as in :
Expand|Select|Wrap|Line Numbers
  1. For Each listset in DB.TableDefs
May 2 '10 #7
Thank you ADezil and NeoPa for your input. I will give it a shot on Monday or Tuesday.

Frank
May 2 '10 #8
NeoPa
32,556 Expert Mod 16PB
A pleasure :)

Let us know how you get on.
May 3 '10 #9
MMcCarthy
14,534 Expert Mod 8TB
I would just mention here that when using DAO in Access you have to explicitly declare the variables as DAO type or they will default to ADO.

So in this case your recordset declaration has to be:

Expand|Select|Wrap|Line Numbers
  1. Dim listset As DAO.Recordset
Jun 12 '10 #10
NeoPa
32,556 Expert Mod 16PB
Good point Mary. I overlooked that one.
Jun 13 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Erica | last post by:
Here is the error I get. Line 13 is the 'do while f.AtEndOfStream = false' line. Your help is very much appreciated! Microsoft VBScript runtime error '800a01a8' Object required: 'f' ...
5
by: kildareguy | last post by:
I am getting this error when running a module in Access 2002...anyone know what it is? and how to correct it?
2
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that...
5
by: jwa6 | last post by:
I get an runtime error w/ this code If Me!Obj = 5100 Then runtime error 13 type mismatch what is this testing for? IE: 5100 jim
6
by: Bill Patel | last post by:
I am getting Runtime error on line 50. Please Help. Thank You Bill 1 <%@ Page Language="VB" %> 2 <%@ import Namespace="System.Data" %> 3 <%@ import Namespace="System.Data.SqlClient"...
1
by: PaulieS | last post by:
Hi all. Am migrating a customer from IIS5 on W2K server to IIS6 on W2K3. Zipped all the websites and unzipped them to the identical locations on new server. Used IISMT to migrate metabase. ...
0
by: Kirk | last post by:
I'm trying to use a Web Service to be a Remoting client of an existing ..NET 2.0 server. But I get the following error when I try to use System.Runtime.Remoting.Channels.Http in my WebService. ...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
7
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.