473,413 Members | 1,696 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,413 software developers and data experts.

Addinf firelds to tables remotely

Is there a way to add fields to a table from a query?

I have a database with back end tables and if I make changes to the front
end that include adding extra fields to a table, I have to trust the user to
update the tables. Quite often this may just be the addition of a Yes/No
tick box or something similar. Obviously if they don't quite do it right,
the updated front end won't work.

I want to be able to perhaps add a query or something that will allow the
user to do an update of the front end, press a buton on a form that will
activate a query to update the tables with what I want.

Thanks in Advance for any assistance.
Feb 11 '06 #1
1 1452
On Sat, 11 Feb 2006 15:14:42 +0800, "Scott" <sc********@iinet.net> wrote:
Is there a way to add fields to a table from a query?

I have a database with back end tables and if I make changes to the front
end that include adding extra fields to a table, I have to trust the user to
update the tables. Quite often this may just be the addition of a Yes/No
tick box or something similar. Obviously if they don't quite do it right,
the updated front end won't work.

I want to be able to perhaps add a query or something that will allow the
user to do an update of the front end, press a buton on a form that will
activate a query to update the tables with what I want.

Thanks in Advance for any assistance.


You can do this with an ALTER TABLE query (see help for details) but I generally
use DAO for this purpose -

Function fAddNewFieldToLinkedTable(strTableName As String, strPKey As String, _
strfieldname As String, intFieldType As Integer, Optional intFieldSize As
Integer, Optional vDefVal As Variant)
'opens a linked table directly and adds new field to seleted table

Dim strBEPath As String
Dim Bfdb As Database
Dim strSQL As String
Dim rst As Recordset
Dim vChk As Variant
Dim tdf As TableDef
Dim fld As Field

On Error GoTo HandleIt

strBEPath = CurrentDb().TableDefs(strTableName).Connect
strBEPath = Right(strBEPath, Len(strBEPath) - 10)

Set Bfdb = CurrentDb()
strSQL = "SELECT * FROM " & strTableName & " WHERE ((" & strPKey & ")=" &
DMin(strPKey, strTableName) & ");"
Set rst = Bfdb.OpenRecordset(strSQL, dbOpenSnapshot)
With rst
If .RecordCount > 0 Then
vChk = .Fields(strfieldname)
vChk = True
End If
.Close
End With

AddField:
If vChk = False Then
Set Bfdb = Nothing
Set Bfdb = DBEngine(0).OpenDatabase(strBEPath)
Set tdf = Bfdb.TableDefs(strTableName)
Set fld = tdf.CreateField(strfieldname, intFieldType, intFieldSize)
If Not IsMissing(vDefVal) Then
fld.DefaultValue = vDefVal
End If
tdf.Fields.Append fld
End If
OutHere:
If Not (fld Is Nothing) Then Set fld = Nothing
If Not (tdf Is Nothing) Then Set tdf = Nothing
If Not (rst Is Nothing) Then Set rst = Nothing
If Not (Bfdb Is Nothing) Then Set Bfdb = Nothing
Exit Function

HandleIt:
Select Case Err
Case 0
Resume Next
Case 3265 'field does not exist
rst.Close
vChk = False
Resume AddField
Case Else
Beep
MsgBox Err & " " & Err.Description, vbCritical + vbOKOnly, "Error
adding new field to table"
Resume OutHere
End Select

End Function

Wayne Gillespie
Gosford NSW Australia
Feb 11 '06 #2

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

Similar topics

1
by: Bennett Haselton | last post by:
I want to get an ASP.Net hosting account with my ISP, and I'm trying to find out what level of access to the server is requried in order for me to view the server in Server Explorer in Visual...
1
by: Thomas Bartkus | last post by:
What can I do about my Access Linked ODBC tables showing the #Deleted error? I am using MySQL ODBC 3.51 Driver and Access 2000. I can create linked tables to the MySQL database running remotely...
1
by: Bennett Haselton | last post by:
I want to get an ASP.Net hosting account with my ISP, and I'm trying to find out what level of access to the server is requried in order for me to view the server in Server Explorer in Visual...
0
by: sunrt | last post by:
We have an As400 system that has program which executes batch files which resides on the SQL server 7.0 computer . Those batch files run SQL server jobs using isql. The whole idea about this is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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...

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.