Adding fields to tables

M

Max Murison

I have been trying to write code to pass perameters to a module that will
add a field to an existing table in a backend database.
All the perameters work apart from the table name. I have tried many
permutations of the table name

I ran this from the Debug window:
CreateTblField "C:\Logbook\Logdat97.mdb", "dbs.TableDefs!Patients",
"EarSize", dbText, 20
Max

This is the code I have used:


Function CreateTblField(strDBName As String, strTblName As String,
strFieldName As String, _
strFieldType As String, strFieldSize As Integer)
On Error GoTo Err_CreateTblField
Dim dbs As Database, tdf As TableDef, tdfTemp As String
Dim fldInitial As Field
Set dbs = DBEngine.OpenDatabase(strDBName)
Set tdf = "dbs.TableDefs!" & strTblName
' Create new Field object.
Set fldInitial = tdf.CreateField(strFieldName, strFieldType,
strFieldSize)
tdf.Fields.Append fldInitial
tdf.Fields.Refresh
Set dbs = Nothing

Thanks.
 
R

Roger Carlson

You want something like this instead:

Set tdf = dbs.TableDefs(strTblName}

You might also want to look at my website at the following two sample
databases: SQLDAOloader2K.mdb and SQLLoader2K.mdb. They may give you some
more ideas.
 
N

Nigel Bennett

I use this function

Dim dbs As Database
Dim location As String

'
Set dbs = OpenDatabase(location)


On Error Resume Next
'
dbs.Execute "ALTER TABLE invoices ADD COLUMN ordertype
text(50)"

Nigel Bennett
-----Original Message-----
You want something like this instead:

Set tdf = dbs.TableDefs(strTblName}

You might also want to look at my website at the following two sample
databases: SQLDAOloader2K.mdb and SQLLoader2K.mdb. They may give you some
more ideas.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org


"Max Murison" <murison@NO SPAMplastic-
surgery.demon.co.uk> wrote in messageCreateTblField "C:\Logbook\Logdat97.mdb", "dbs.TableDefs!
Patients",
 
M

Max Murison

Thanks, it worked a treat.

MAX

Roger Carlson said:
You want something like this instead:

Set tdf = dbs.TableDefs(strTblName}

You might also want to look at my website at the following two sample
databases: SQLDAOloader2K.mdb and SQLLoader2K.mdb. They may give you some
more ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top