PC Review


Reply
Thread Tools Rate Thread

add field to linked table

 
 
=?Utf-8?B?Um95Y2U=?=
Guest
Posts: n/a
 
      9th Jun 2005
I have a Access 2000 data database containing only tables linked to a Program
database. I need to alter the structure of one of the data tables. (Add a
field.) I would like to do it from code in the Programs database. ALTER
table does not work on linked tables.

Is there any way to do this?

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      9th Jun 2005
You could try adding an IN clause, e.g.:
ALTER TABLE Table1 IN 'c:\MyDatabase.mdb' ...

If that doesn't work, you could OpenDatabase(), and run the SQL statement
against that database variable.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Royce" <(E-Mail Removed)> wrote in message
news:2A852F31-93A3-4A53-8E23-(E-Mail Removed)...
>I have a Access 2000 data database containing only tables linked to a
>Program
> database. I need to alter the structure of one of the data tables. (Add a
> field.) I would like to do it from code in the Programs database. ALTER
> table does not work on linked tables.
>
> Is there any way to do this?
>



 
Reply With Quote
 
Duane Hookom
Guest
Posts: n/a
 
      9th Jun 2005
I usually call some DAO code like the following (needs error handling):

Function AddField(pstrTable As String, pstrField As String, _
intFieldType As DataTypeEnum) As Boolean
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim strRemoteDB As String

Set db = CurrentDb
Set td = db.TableDefs(pstrTable)
If Len(td.Connect) > 0 Then
strRemoteDB = Mid(td.Connect, 11)
Set td = Nothing
Set db = OpenDatabase(strRemoteDB)
Set td = db.TableDefs(pstrTable)
End If
With td
.Fields.Append .CreateField(pstrField, intFieldType)
End With
Set td = Nothing
Set db = Nothing
End Function


--
Duane Hookom
MS Access MVP


"Allen Browne" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You could try adding an IN clause, e.g.:
> ALTER TABLE Table1 IN 'c:\MyDatabase.mdb' ...
>
> If that doesn't work, you could OpenDatabase(), and run the SQL statement
> against that database variable.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Royce" <(E-Mail Removed)> wrote in message
> news:2A852F31-93A3-4A53-8E23-(E-Mail Removed)...
>>I have a Access 2000 data database containing only tables linked to a
>>Program
>> database. I need to alter the structure of one of the data tables. (Add
>> a
>> field.) I would like to do it from code in the Programs database.
>> ALTER
>> table does not work on linked tables.
>>
>> Is there any way to do this?
>>

>
>



 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      9th Jun 2005
Thanks, Duane.

That's a good approach.
Doesn't look like the DDL works.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Duane Hookom" <duanehookom@NO_SPAMhotmail.com> wrote in message
news:(E-Mail Removed)...
>I usually call some DAO code like the following (needs error handling):
>
> Function AddField(pstrTable As String, pstrField As String, _
> intFieldType As DataTypeEnum) As Boolean
> Dim db As DAO.Database
> Dim td As DAO.TableDef
> Dim strRemoteDB As String
>
> Set db = CurrentDb
> Set td = db.TableDefs(pstrTable)
> If Len(td.Connect) > 0 Then
> strRemoteDB = Mid(td.Connect, 11)
> Set td = Nothing
> Set db = OpenDatabase(strRemoteDB)
> Set td = db.TableDefs(pstrTable)
> End If
> With td
> .Fields.Append .CreateField(pstrField, intFieldType)
> End With
> Set td = Nothing
> Set db = Nothing
> End Function
>
>
> --
> Duane Hookom
> MS Access MVP
>
>
> "Allen Browne" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> You could try adding an IN clause, e.g.:
>> ALTER TABLE Table1 IN 'c:\MyDatabase.mdb' ...
>>
>> If that doesn't work, you could OpenDatabase(), and run the SQL statement
>> against that database variable.
>>
>>
>> "Royce" <(E-Mail Removed)> wrote in message
>> news:2A852F31-93A3-4A53-8E23-(E-Mail Removed)...
>>>I have a Access 2000 data database containing only tables linked to a
>>>Program
>>> database. I need to alter the structure of one of the data tables. (Add
>>> a
>>> field.) I would like to do it from code in the Programs database.
>>> ALTER
>>> table does not work on linked tables.
>>>
>>> Is there any way to do this?



 
Reply With Quote
 
=?Utf-8?B?Um95Y2U=?=
Guest
Posts: n/a
 
      9th Jun 2005
Thanks for the sample code. I had tried a similiar function, that didn't
work. Unfortunately, I didn't save the original code, so I don't know what I
was doing wrong. But I think it was something I was doing with the
OpenDatabase. It kept wanting to open the ODBC connection box.

Thanks again,
Royce

"Duane Hookom" wrote:

> I usually call some DAO code like the following (needs error handling):
>
> Function AddField(pstrTable As String, pstrField As String, _
> intFieldType As DataTypeEnum) As Boolean
> Dim db As DAO.Database
> Dim td As DAO.TableDef
> Dim strRemoteDB As String
>
> Set db = CurrentDb
> Set td = db.TableDefs(pstrTable)
> If Len(td.Connect) > 0 Then
> strRemoteDB = Mid(td.Connect, 11)
> Set td = Nothing
> Set db = OpenDatabase(strRemoteDB)
> Set td = db.TableDefs(pstrTable)
> End If
> With td
> .Fields.Append .CreateField(pstrField, intFieldType)
> End With
> Set td = Nothing
> Set db = Nothing
> End Function
>
>
> --
> Duane Hookom
> MS Access MVP
>
>
> "Allen Browne" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > You could try adding an IN clause, e.g.:
> > ALTER TABLE Table1 IN 'c:\MyDatabase.mdb' ...
> >
> > If that doesn't work, you could OpenDatabase(), and run the SQL statement
> > against that database variable.
> >
> > --
> > Allen Browne - Microsoft MVP. Perth, Western Australia.
> > Tips for Access users - http://allenbrowne.com/tips.html
> > Reply to group, rather than allenbrowne at mvps dot org.
> >
> > "Royce" <(E-Mail Removed)> wrote in message
> > news:2A852F31-93A3-4A53-8E23-(E-Mail Removed)...
> >>I have a Access 2000 data database containing only tables linked to a
> >>Program
> >> database. I need to alter the structure of one of the data tables. (Add
> >> a
> >> field.) I would like to do it from code in the Programs database.
> >> ALTER
> >> table does not work on linked tables.
> >>
> >> Is there any way to do this?
> >>

> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?TmlnZWw=?=
Guest
Posts: n/a
 
      9th Jun 2005
I have used this before on linked tables (as long as they are access) and it
works

Set dbs = OpenDatabase(location of table)

dbs.Execute "ALTER TABLE invoices ADD COLUMN ordertype text(50)"

"Royce" wrote:

> I have a Access 2000 data database containing only tables linked to a Program
> database. I need to alter the structure of one of the data tables. (Add a
> field.) I would like to do it from code in the Programs database. ALTER
> table does not work on linked tables.
>
> Is there any way to do this?
>

 
Reply With Quote
 
=?Utf-8?B?Um95Y2U=?=
Guest
Posts: n/a
 
      10th Jun 2005
One of the things I have often found frustrating about Access is the subtle
differences about when something will work. Over the years I've learned many
of them, but I still run into things from time to time that can be very
frustrating to figure out. I know there are some documented problems with
the database object. In this case, I actually found and tried some sample
code from the Northwind databae, which didn't work in my App!

Royce

"Allen Browne" wrote:

> Thanks, Duane.
>
> That's a good approach.
> Doesn't look like the DDL works.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Duane Hookom" <duanehookom@NO_SPAMhotmail.com> wrote in message
> news:(E-Mail Removed)...
> >I usually call some DAO code like the following (needs error handling):
> >
> > Function AddField(pstrTable As String, pstrField As String, _
> > intFieldType As DataTypeEnum) As Boolean
> > Dim db As DAO.Database
> > Dim td As DAO.TableDef
> > Dim strRemoteDB As String
> >
> > Set db = CurrentDb
> > Set td = db.TableDefs(pstrTable)
> > If Len(td.Connect) > 0 Then
> > strRemoteDB = Mid(td.Connect, 11)
> > Set td = Nothing
> > Set db = OpenDatabase(strRemoteDB)
> > Set td = db.TableDefs(pstrTable)
> > End If
> > With td
> > .Fields.Append .CreateField(pstrField, intFieldType)
> > End With
> > Set td = Nothing
> > Set db = Nothing
> > End Function
> >
> >
> > --
> > Duane Hookom
> > MS Access MVP
> >
> >
> > "Allen Browne" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> You could try adding an IN clause, e.g.:
> >> ALTER TABLE Table1 IN 'c:\MyDatabase.mdb' ...
> >>
> >> If that doesn't work, you could OpenDatabase(), and run the SQL statement
> >> against that database variable.
> >>
> >>
> >> "Royce" <(E-Mail Removed)> wrote in message
> >> news:2A852F31-93A3-4A53-8E23-(E-Mail Removed)...
> >>>I have a Access 2000 data database containing only tables linked to a
> >>>Program
> >>> database. I need to alter the structure of one of the data tables. (Add
> >>> a
> >>> field.) I would like to do it from code in the Programs database.
> >>> ALTER
> >>> table does not work on linked tables.
> >>>
> >>> Is there any way to do this?

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add another field into a linked table =?Utf-8?B?SmVzIGluIFRY?= Microsoft Access Getting Started 5 7th Mar 2007 10:20 PM
Linked table not seeing last field SAC Microsoft Access 0 15th Sep 2006 04:31 PM
Add new field to linked table Rob Microsoft Access 2 12th Mar 2006 02:25 PM
How do you get the name of a field from a linked table? =?Utf-8?B?Z2c=?= Microsoft Access Form Coding 4 2nd Nov 2005 01:55 AM
Only allow recor addition to a table if linked table/field is true =?Utf-8?B?Q2hyaXNCYXJuZXM=?= Microsoft Access Database Table Design 0 26th Jan 2005 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:42 PM.