473,396 Members | 2,037 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.

Access 2003, sudden code failure

344 Expert 100+
Below is a section of code that I have been running for over 6 years on many databases. It helps me create tables quickly. Today, with no changes, when it gets to the create property line, if falls over with Error 13, Type Mismatch. On every property line, on every database.

Any idea what is going on please.
Expand|Select|Wrap|Line Numbers
  1.     If Len(rs!Description & "") > 0 Then
  2.         Set prp = fld.CreateProperty("Description", dbText, rs!Description)
  3.         fld.Properties.Append prp
  4.     End If
  5.     If Len(rs!RowSource & "") > 0 Then
  6.         Set prp = fld.CreateProperty("DisplayControl", 3, 111)
  7.         fld.Properties.Append prp
  8.  
Sep 16 '14 #1

✓ answered by zmbd

Running thru your code.
The only thing I would change is to explicitly set:
Expand|Select|Wrap|Line Numbers
  1. '...
  2. Dim db As DAO.Database
  3. Dim td As DAO.TableDef
  4. Dim fld As DAO.Field
  5. Dim prp As DAO.Property
  6. '...
  7. Dim rs As DAO.Recordset
  8. ...
The posted code you ran just fine on my ACC2010 development PC. I did however set the DAO explicitly.

So the first thing I would check would be the: Sheet1 the actual data entry in the recordset. Verfiy that something has not corrupted the recordset.

Next: Tools>References... I do not expect this to be the issue.

Then I would set either DAO or ADO depending on your preference for development. (BTW: As of late, it is considered preferable to explicitly declaire DAO/ADO/etc so as to prevent library issues)


You say you make a ton of tables... the same database over and over again?

11 1388
twinnyfo
3,653 Expert Mod 2GB
Lysander,

My condolences! I've had stuff like this happen to me before, too. Have you had any recent updates to MS Office? You mention Access 2003, and such weird behavior seems to fit more in a switch to 2007/2010, but not a minor version change (but which has bitten me in the past).

I am sure you have troubleshot to find out if rs!Description is, in fact, text?

Another one of the headache-inducing idiotsyncracies of MS Access.... But what can you do? It's all we got!
Sep 16 '14 #2
Lysander
344 Expert 100+
Nope, no updates, no new software, last thing I loaded was a game, 6 months ago, and code was working after that. Code actually worked last Friday. As it is failing on all databases, not a database issue, either my references have got corrupt, or something else is screwing up my PC. This is critical time-saving code I have been using for years. Thankfully, the table I need to create is only 12 fields this time, so I can do it manualy this afternoon, but, a real pain in the proverbials.

Description, on the table, is indeed text. It says things like "This is women who have given birth" or "Total Pregnacies so far" etc.
Sep 16 '14 #3
zmbd
5,501 Expert Mod 4TB
run the debug compile and option setups as descriped in the general debugging steps as outlined here:
> Before Posting (VBA or SQL) Code

I suspect that you don't have option explicit set and that there is a typo somewhere; however, without the remaining code that is only a guess (^_^)
Sep 16 '14 #4
Lysander
344 Expert 100+
Sadly, I wish that was the answer, but, I have been forcing Option Explict since Access 2.5, when it first appeared.

I can't post the full code, I don't think, they limit to 20 lines, but I will try. Nothing has changed for 6 years. It worked on Friday, failed today.

Here is the full code, if they let me post it
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit 
  3.  
  4. Sub test()
  5. Dim db As Database
  6. Dim td As TableDef
  7. Dim fld As Field
  8. Dim prp As Property
  9. Dim i As Integer, j As Integer, var As Variant
  10. Dim rs As Recordset
  11. Set db = CurrentDb
  12. Set rs = db.OpenRecordset("SELECT id,Caption, Name, Description, Type, Size, RowSource FROM Sheet1 ORDER BY ID;")
  13. Set td = db.TableDefs("tblSchoolSurvey")
  14. While Not rs.EOF
  15. Select Case rs!Type
  16. Case "dblong"
  17.     Set fld = td.CreateField(rs!Name, dbLong)
  18. Case "dbText"
  19.     Set fld = td.CreateField(rs!Name, dbText, rs!Size)
  20. End Select
  21. td.Fields.Append fld
  22.     If Len(rs!Caption & "") > 0 Then
  23.         Set prp = fld.CreateProperty("Caption", dbText, rs!Caption)
  24.         fld.Properties.Append prp
  25.     End If
  26.     If Len(rs!Description & "") > 0 Then
  27.         Set prp = fld.CreateProperty("Description", dbText, rs!Description)
  28.         fld.Properties.Append prp
  29.     End If
  30.     If Len(rs!RowSource & "") > 0 Then
  31.         Set prp = fld.CreateProperty("DisplayControl", 3, 111)
  32.         fld.Properties.Append prp
  33.         Set prp = fld.CreateProperty("RowSourceType", 10, "Table/Query")
  34.         fld.Properties.Append prp
  35.         Set prp = fld.CreateProperty("RowSource", 12, rs!RowSource)
  36.         fld.Properties.Append prp
  37.         Set prp = fld.CreateProperty("BoundColumn", 3, 1)
  38.         fld.Properties.Append prp
  39.         Set prp = fld.CreateProperty("ColumnCount", 3, 2)
  40.         fld.Properties.Append prp
  41.         Set prp = fld.CreateProperty("ColumnHeads", 1, False)
  42.         fld.Properties.Append prp
  43.         Set prp = fld.CreateProperty("ColumnWidths", 10, "567;2268")
  44.         fld.Properties.Append prp
  45.         Set prp = fld.CreateProperty("ListWidth", 10, "2835twip")
  46.         fld.Properties.Append prp
  47.         Set prp = fld.CreateProperty("LimitToList", 1, True)
  48.         fld.Properties.Append prp
  49.     End If
  50.     rs.MoveNext
  51. Wend
  52. rs.Close
  53. Set rs = Nothing
  54. Set prp = Nothing
  55. Set fld = Nothing
  56. Set td = Nothing
  57. Set db = Nothing
  58.  
  59. End Sub
Sep 16 '14 #5
twinnyfo
3,653 Expert Mod 2GB
And you said your cod3e is dying on Line 25 with a Type Mismatch? Try inserting
Expand|Select|Wrap|Line Numbers
  1. Debug.Print rst!Description
after line 24 just to see what the VB sees in that field. Totally strange that htis would work Friday, but not today........
Sep 16 '14 #6
zmbd
5,501 Expert Mod 4TB
Running thru your code.
The only thing I would change is to explicitly set:
Expand|Select|Wrap|Line Numbers
  1. '...
  2. Dim db As DAO.Database
  3. Dim td As DAO.TableDef
  4. Dim fld As DAO.Field
  5. Dim prp As DAO.Property
  6. '...
  7. Dim rs As DAO.Recordset
  8. ...
The posted code you ran just fine on my ACC2010 development PC. I did however set the DAO explicitly.

So the first thing I would check would be the: Sheet1 the actual data entry in the recordset. Verfiy that something has not corrupted the recordset.

Next: Tools>References... I do not expect this to be the issue.

Then I would set either DAO or ADO depending on your preference for development. (BTW: As of late, it is considered preferable to explicitly declaire DAO/ADO/etc so as to prevent library issues)


You say you make a ton of tables... the same database over and over again?
Sep 16 '14 #7
Lysander
344 Expert 100+
twinnyfo, the rs!description says "Lookup tlkStatus". I copied the line into the immeditate window and used "FRED" and "PETER" as the text, same failure.
Sep 17 '14 #8
Lysander
344 Expert 100+
zmbd
Thank you. Hugs and love.
Putting DAO. in front of the declarations solved the problem.

I can only imagine that a game or something else I have loaded has used Access and caused a conflict between DAO and ADO.

And yes, I have been using this code, on over a dozen databases, over and over again since 2006

All working now.

Thanks again.
Sep 17 '14 #9
twinnyfo
3,653 Expert Mod 2GB
Lysander,

Great to hear that you found success!
Sep 17 '14 #10
zmbd
5,501 Expert Mod 4TB
*(^_^)*
Warm Fuzzies... need that today.. the lab has Grimlins again.

Be interesting to find out what and why the game changed things in the system. (^_^) Wouldn't surprise me if there was some update to the DLLs in the commonfiles folder - or they may have added the ADO reference. ACC2003 is supposed to be DAO by default;however, some run with both ADO and DAO set and that will cause issues.

IMHO: Poor programming on the gammers part if that is what happened - I was taught that you didn't touch other program's cores nor depedencies. sigh. old school

Something else I wanted to mention:
Expand|Select|Wrap|Line Numbers
  1. (air code...)
  2. Set rs = db.OpenRecordset("SELECT 
  3. id,Caption, 
  4. NameDescription,
  5.  TypeSize
  6. , RowSource FROM Sheet1 ORDER BY ID;")
There are a few reserved words/tokens in your table/code, lines 4 and 5 above. These will eventully give you issues - especially if you upgrade to a newer version of Office/Access or attempt to push the data up to a mature RDBS (MySQL, SQL Server, Oracle, etc...) or even to SharePoint (IMHO:yuck).

You might find the following usefull:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access
Sep 17 '14 #11
NeoPa
32,556 Expert Mod 16PB
Glad to see this one resolved Lysander old friend :-)

I would suggest that it is good practice (always has been but more important nowadays) to use DAO. and ADO. references explicitly in code. This is because they each use object names that are also used by the other. When not specified explicitly Access will default to one or other depending on version, and possibly even, other things I'm unaware of. However that is, I expect for reasons not clearly understood at this time (certainly not by me with current info), I believe the way Access defaulted this for you recently changed from one to the other and you were left with a confusing mess to deal with.

Knowing that you're already a fan of the Option Explicit in your coding, I expect you'll feel right at home taking this one on board. They're very similar concepts in my view.

All the best -Ade.
Sep 18 '14 #12

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

Similar topics

0
by: Jer | last post by:
I am the owner of a database with other users. I have given all users db_owner role. My server is MSDE 2000. I use the following code to import a spreadsheet: docmd.transferspreadsheet acImport,...
0
by: Mike | last post by:
Our Product is 100% free, we are not trying to sell anything here. MyGeneration is a .NET Code Generator that allows you to create templates in either VBScript or JScript, it also serves up all...
9
by: Dave Brydon | last post by:
Access 2003: I currently apply my Postal/Zip Code Format based off the Country Selected; the way I do it is by checking on the country; using the forms "On Current" event procedure, then I use...
13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
3
by: willockguard-newsgoups | last post by:
A database converted from Access 97 to Access 2003 contained code to load jpeg photos into Microsoft Photo Editor. As Office 2003 Professional does not come with Microsoft Photo Editor, is there...
1
by: Jer | last post by:
I have an Access Project front-end to an MSDE database. I have given all users db_owner role. My server is MSDE 2000. I use the following code to import a spreadsheet: docmd.transferspreadsheet...
1
by: PW | last post by:
Hi, All of a sudden one of our clients can't use her application. She gets "You don't have exclusive access to your database at this time" when trying to open our application. The only thing...
2
by: Mahesh Shinde | last post by:
Hi. I am a student of MCA. Please I need your help for connection between VB 6.0 and Access 2003 by code. Because first time I am working on VB. Can you send me the login page coding?
4
by: Sheree | last post by:
I have some Access 2003 VBA code that looks like this: Private Sub SubName() Me.FilterOn = True Me.Filter = "" ' Me.FilterOn = False ' Me.Requery x = msgbox("Filter Cleared. Number of...
1
by: Alan Yim | last post by:
Hi folks, My company recently upgraded our Office suite from 2003 to 2010. The problem in particular is with an Access database that was originally designed in Access 2003. The code in question...
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
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,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.