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

Adding New Field To Access Table

After reviewing the messages on google and using the Access 2000
developers handbook I came up with the following code to add a field
to an access table.
I'm working in Access 2002, and the code below steps through without
a glich. Problem is it doesn't add the column to the table.

Any help appreciated:

Thanks,
Tom

using VB 6 SP 5, windowx XP, Access 2002 , DSNless connection string.
ADO 2.8

Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim cat As ADOX.Catalog
Dim c As ADOX.Column
Dim intI As Integer
Dim FoundIt As Boolean
Dim sqlStr As String
Dim tbl As ADOX.Table

On Error GoTo ErrorCheck

FoundIt = False

Set rs = New ADODB.Recordset
rs.Open "ADTData", objConn
For intI = 0 To rs.Fields.Count - 1
Set fld = rs.Fields(intI)
If fld.Name = "Trigger" Then
FoundIt = True
Exit For
End If
Next intI
rs.Close
Set rs = Nothing

If objConn.State = adStateOpen Then
If Not FoundIt Then
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
Set c = New ADOX.Column
c.Name = "Trigger"
c.Type = adChar 'I've also used every version of char I could
'find
c.DefinedSize = 3
cat.ActiveConnection = objConn
tbl.Name = "ADTData"
With tbl.Columns
.Append c
End With
cat.Tables.Refresh
Set cat = Nothing
Set tbl = Nothing
End If
End If

Exit Sub
ErrorCheck:
MsgBox "Error in AddTriggerField" & Err.Description,
vbInformation, "Error"
End Sub
Nov 13 '05 #1
2 1931
Maybe it's just because it's late, but I don't see where this line gets a value:

cat.ActiveConnection = objConn

what is the value of objConn? I don't see anything like

Set objConn=CurrentProject.Connection

or anything like that....
Nov 13 '05 #2
Maybe it's just because it's late, but I don't see where this line gets a value:

cat.ActiveConnection = objConn

what is the value of objConn? I don't see anything like

Set objConn=CurrentProject.Connection

or anything like that....
Nov 13 '05 #3

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

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
2
by: Robin S. | last post by:
This is an "Add product" form. The user will enter a ProductNo (catalog number), select a Product Class (from cascading combo boxes) and then click a button to create the product. When a...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
1
by: Randy | last post by:
I built and employment report from the employment table. I then had to add a field to the table. I now need to add that field to the report. I can't seem to be able to do that by clicking on...
12
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
5
by: rdemyan via AccessMonster.com | last post by:
I have a table with about 80 fields. I'm using an import process to populate the table. It works fine, except for the following: Users generally don't specify values for a lot of numerical...
2
by: dympna | last post by:
Hi can anyone suggest a fix for this... as I am a novice in access. I have created a training table with the following fields Employee Name - joe Training Received - Fork lift Date Received...
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...
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.