473,399 Members | 2,146 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,399 software developers and data experts.

Check for field in tabledefs prior to append

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 to every table in the collection
Dim strSQL As String
Dim db As Database, tdf As TableDef, intI As Integer

Set db = CurrentDb

For intI = 0 To db.TableDefs.Count - 1
Set tdf = db.TableDefs(intI)
' Skip system tables
If Left(tdf.Name, 4) <"MSys" Then
tdf.Fields.Append tdf.CreateField("Source_tbl", dbText,
15)
strSQL = "UPDATE [" & tdf.Name & "] SET Source_tbl = " _
& "'" & tdf.Name & "';"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
Next

End Sub

Thanks,

Tim Mills-Groninger
Jun 27 '08 #1
2 2194
On Tue, 22 Apr 2008 14:11:20 -0700 (PDT), timmg
<tm*************@gmail.comwrote:

You can walk the Fields collection to find out if a name exists.
The other thing you can do is to simply let it happen and have a good
error handler (which I'm sure you omitted here for simplicity :-) )
deal with the aftermath.

-Tom.

>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 to every table in the collection
Dim strSQL As String
Dim db As Database, tdf As TableDef, intI As Integer

Set db = CurrentDb

For intI = 0 To db.TableDefs.Count - 1
Set tdf = db.TableDefs(intI)
' Skip system tables
If Left(tdf.Name, 4) <"MSys" Then
tdf.Fields.Append tdf.CreateField("Source_tbl", dbText,
15)
strSQL = "UPDATE [" & tdf.Name & "] SET Source_tbl = " _
& "'" & tdf.Name & "';"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
Next

End Sub

Thanks,

Tim Mills-Groninger
Jun 27 '08 #2
On Apr 23, 12:27*am, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
...
>
You can walk the Fields collection to find out if a name exists.
The other thing you can do is to simply let it happen and have a good
error handler (which I'm sure you omitted here for simplicity :-) )
deal with the aftermath.
Thanks, I pinged the group to see if there was a more elegant solution
than looping through the field name. Maybe error handling is it -
which I naturally ommitted for simplicity (being simple minded counts,
doesn't it?)

Tim Mills-Groninger
Jun 27 '08 #3

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

Similar topics

2
by: Bob | last post by:
I have been looking at the code for MedianFind(pDte As String) from the following thread from UtterAccess.com: "Finding Median average grouped by field" I have been able to get it to run using...
6
by: David Gartrell | last post by:
Hi i'm trying to import an Excel Spreadsheet into Access2000 but the data types for two of the fields in my imported table are being identified incorrectly. Is there a way of using some VB code in...
7
by: No Spam | last post by:
Dear Access 2003 users, Can anyone assist me with creating either code (preferred) or a query that would remove a single field (called ID) from a table? And as a bonus question, can anyone...
8
by: Chris A via AccessMonster.com | last post by:
I have an interesting problem that I have yet to come accross that I can't change data structure on because it is an export from filemaker I am reformatting for another dept. anyway. I have a table...
16
by: Mark | last post by:
Hello. I am attempting to use AppendChunk() to write binary data to a memo field in Access 2000. My initial call to AppendChunk() results in a data type conversion error. Any suggestions? Here...
4
by: Greg Strong | last post by:
Hello All, Ok I've read it is not necessarily a good ideal to create a hyperlink field in a database, but I've tried. I've also read that a hyperlink field is a memo field with attributes of...
2
by: DaveGriffiths70 | last post by:
I can create a table in VBA using standard DAO, but I have a problem with my ID field. I make it a long integer, that bit's easy, but I can't see how to make that field the primary key field, with...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
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: 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
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
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
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,...
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.