473,511 Members | 16,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TableDefs not recognized (I think?)

21 New Member
I am writing some code to seen if an import error table has been created.

When using the VBA editor in Access and I type in lowerrcase the following two statements
dim db as DAO.database
dim td as DAO.tabledef

it corrects it to
Dim db As DAO.Database
Dim td As DAO.TableDef
recognising the reserved words each time. However typing
Dim mydefs As DAO.TableDefs
is reverting to lowercase 'tabledefs' AND no subsequent code referring to 'mydefs' or any code with 'TableDefs' appears to be recognized or actioned.
This is happening regardless of whether I use 'DAO' or not.
Am I missing something or using the wrong syntax for tabledefs? Anybody else had the same problem?

Any help thankfully received.
Sep 1 '10 #1
6 4222
gershwyn
122 New Member
The TableDefs collection is a member of the Database object. I get an error when I refer to tabledefs or dao.tabledefs, but the following works fine:

Expand|Select|Wrap|Line Numbers
  1. msgbox CurrentDb.TableDefs.Count
Sep 1 '10 #2
missinglinq
3,532 Recognized Expert Specialist
It think it should be TableDef, as in the example that works, not TableDefs, which doesn't. Try dropping the s from the end.

Linq ;0)>
Sep 1 '10 #3
Deekay
21 New Member
Thank you Gershwyn and Missingling for your replies.
db.tabledefs.count appears to be working so that is recognized. Tabledefs is definately different to tabledef I believe where the first refers to the collection of tables and the second is used to refer to an individual table. But following on from my previous post...

str = mydefs.td.name (where str is a string variable)

is generating an error on compiling as not recognized.

Any further thoughts from anyone?
Sep 1 '10 #4
gershwyn
122 New Member
There is no member of the tabledefs collection called "td" so that will give an error. td is an object variable you've defined yourself.

The syntax to get the name of the first tableDef object in the collection would be this:
Expand|Select|Wrap|Line Numbers
  1. tblName = mydefs(0).Name
If you know the name, you can also refer to it this way:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print myDefs("TableName").RecordCount
Note: Str is the name of a built in function in Access, so I would avoid using it as a variable name.
Sep 1 '10 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
As Linq and Gershwyn have indicated, you appear to be trying to access the tabledefs collection itself instead of the relevant tabledef contained within the collection. I'm not sure why you'd want to do so, as all the applications of the tabledefs collection I know of result from retrieving a given tabledef from the collection and working on that.

The Tabledefs() collection is not an object which you can declare in the way you have tried; it is a container for the objects within it. If you wanted to declare an object as a copy of your tabledefs collection as far as I can tell you'd have to declare it as a Collection object. I don't think this is at all necessary.

I have found that if you use the CurrentDB function to return the Tabledefs collection you can get problems with apparent lack of consistency of updates etc. In these circumstances it is best to declare a new database object, assign it the value of CurrentDB, then refer to the Tabledefs collection of that object for whatever you need to do, as shown in the example below:

Expand|Select|Wrap|Line Numbers
  1. Dim MyDb as Database
  2. Dim MyTableDef as DAO.Tabledef
  3. Set MyDb = CurrentDB
  4. Set MyTableDef = MyDb.Tabledefs("sometablename")
  5. ...
-Stewart
Sep 1 '10 #6
Deekay
21 New Member
Thanks for the various contributions - have solved it now!
(Still strange that in declaring tabledefs it reverts to lowercase whereas other declarations using reserved words capitalise in some way - as has happened using a code based on Stewart's suggestion (and which works) - somthing I'm still not understanding.)
Sep 2 '10 #7

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

Similar topics

2
2403
by: Shane Suebsahakarn | last post by:
Hi all, Does anyone have any idea why creating a table link across a network should be so slow? My front end app follows these steps when opening: * Retrieve all linked tables in the current...
2
2364
by: BUX | last post by:
I have to look in Index property of myTable, but Set myTableDef = myDB.TableDefs(myTable) is so slow .... Do you now any other fast way? thank you
2
10553
by: Dave | last post by:
Help! When I try to run tblimp from the command line I get the following error: tblimp is not recognized as an internal or external command. tblimp.exe is not on my harddrive at all. What...
1
1847
by: melanieab | last post by:
Hi again, With much help, I've finally gotten the Tab key to be recognized when a textbox is in focus, but now I'm having trouble with the up/down keys when they're focused on a custom button (on...
2
2018
by: dee | last post by:
Hi, ASP.NET is not recognized by my system (throws a fit at the site of a .aspx) I have the following setup: - Uninstalled and reinstalled Visual Studio Enterprise Edition.NET - IIS 5 is...
3
2102
by: KRC | last post by:
I am using an external object called WebZinc to help parse web pages in VB.net. I am trying to use a particular method following the example in the help reference but am unable to get VB.net to...
10
16379
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
0
1399
by: srabani | last post by:
Hi Everybody, I am srabani I am new to this site. I am working on VBA DAO and come accross with a code For Each tbl In CurrentDb.TableDefs If InStr(1, tbl.Connect,...
5
8623
by: Kevin Burton | last post by:
I am trying an XSLT transformation using the XslCompiledTransform class. I get an exception when I call the Transform method. It seems to point to these two lines: <xsl:namespace...
2
2197
by: timmg | last post by:
The following code works well except I can't think of an elegant way of checking for the existance of the named field prior to creating it. Suggestions? Public Sub pNewField() 'Add a new field...
0
7423
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
7510
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
5668
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,...
1
5066
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...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.