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

Only add missing fields to table from another Table?

6
I am only trying to add fields that don't exist in the table already from another table list. It works if all the fields are missing but when i already have that field in my table, i get an error. How can i limit the Add column to only the fields that are missing? Any help will be greatly appreciated.

Function AddField()

Dim db As Database
Dim tbl As tableDef
Dim fld As DAO.Field
Dim Str As String
Dim sName As String
Set Criteria = CurrentDb.OpenRecordset("Criteria Table")

Set db = CurrentDb
Set tbl = db.TableDefs("Copy_TEstTable_test")

If Not (Criteria.EOF And Criteria.BOF) Then
Criteria.MoveFirst
Do Until Criteria.EOF = True
Str = [Criteria].[Linked Table]


Criteria.MoveNext
For Each fld In tbl.Fields
If (fld.NAME) = Str Then

Debug.Print fld.NAME; Str
Else

Str2 = "ALTER TABLE Copy_TEstTable_test ADD COLUMN " & Str & " TEXT(25);"
DoCmd.RunSQL (Str2)
End If
Next fld
Loop
Else

End If



Criteria.Close 'Close the recordset
Set rs = Nothing 'Clean up

End Function
Jun 1 '17 #1
0 1173

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

Similar topics

4
by: Fiala | last post by:
Table A +--------+-----------+ | A-num | text | | 1 | | | 2 | | | 3 | | | 4 | | | 5 | | +--------+-----------+
1
by: Glenn P. | last post by:
Sorry, CDMA, I searched this NG on several combinations of words, but I didn't find a relevant hit, so here's my newbie question: I have an Access 2002 table which contains data extracted from...
3
by: sparks | last post by:
I was copying fields from one table to another. IF the var name starts with milk I change it to egg and create it in the destination table. It works fine but I want to copy the description as...
1
by: geronimo_me | last post by:
Hi, I have a small problem I am trying to check if field1 in Table1 matches Field2, Field3 or Field4 in Table2: ie Record 1 Table1 Field1 = ABC Table2
1
by: Shizbart | last post by:
MS Access 97 Beginner/Moderate Level User I am trying to create a Database to track Workouts in MS Access 97. I have one Table named Workouts that contains the following Fields: Workout...
2
by: David - Australia | last post by:
G'day from Australia, I'm hoping some bright spark may be able to help me with this one. I'm sure that it can be done, I've just hit a wall with it. So I'm opening it up. I'm storing student...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
2
by: MrCrunchy | last post by:
Hi All I have 2 tables (as shown below), if i add a row to the FILES TABLE then the myid value is added to mydata list in the PLAYLISTS TABLE, based on the genre matching the myname values. Hope...
6
by: neelsfer | last post by:
I do race timing. I capture race numbers in a subform, a sequential lapnumber is created, and the racenumber and finishtime are appended in realtime to a specific lap number fields in another...
7
by: Eastside newbie | last post by:
Hello! I'm trying to reorganize an old database that has gone through many handlers over the years. I would like to relate 2 tables: Location and Logger_Events. We collect climate data and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.