Connecting Tech Pros Worldwide Forums | Help | Site Map

Altering tables in code

Dixie
Guest
 
Posts: n/a
#1: Nov 13 '05
I wish to be able to do some things to tables in code.

1. Add a field and its properties.
2. Alter the properties of an existing field in a table.
3. Append some extra entries onto the bottom of a table, if they are not
already there.

Any help would be appreciated.

dixie



Br@dley
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Altering tables in code


Dixie <dixie@dogmail.com> wrote:[color=blue]
> I wish to be able to do some things to tables in code.
>
> 1. Add a field and its properties.
> 2. Alter the properties of an existing field in a table.[/color]

Lookup the help on the Tabledef oject.
[color=blue]
> 3. Append some extra entries onto the bottom of a table, if they are
> not already there.[/color]

Search for the record. If it doesn't exist then add it.

eg. (very simplified DAO example)

myRS.FindNext "[myID] = 1"
If myRS.NoMatch then
myRS.AddNew
myRS![myID] = 1
myRS.Update
End If
[color=blue]
> Any help would be appreciated.
>
> dixie[/color]
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


Dixie
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Altering tables in code


Had a quick look at the help file, but it is mainly about creating new
tabledef objects and I don't want to iterate through the tabledef
collection.

Say there was already a table in the database called 'MyTable' and I wanted
to add a field called MyNewField and then say set it as a text field of 25
characters. How do I do that in code.

dixie

"Br@dley" <n0mail@4u.com> wrote in message
news:Penye.14792$oJ.7716@news-server.bigpond.net.au...[color=blue]
> Dixie <dixie@dogmail.com> wrote:[color=green]
>> I wish to be able to do some things to tables in code.
>>
>> 1. Add a field and its properties.
>> 2. Alter the properties of an existing field in a table.[/color]
>
> Lookup the help on the Tabledef oject.
>[color=green]
>> 3. Append some extra entries onto the bottom of a table, if they are
>> not already there.[/color]
>
> Search for the record. If it doesn't exist then add it.
>
> eg. (very simplified DAO example)
>
> myRS.FindNext "[myID] = 1"
> If myRS.NoMatch then
> myRS.AddNew
> myRS![myID] = 1
> myRS.Update
> End If
>[color=green]
>> Any help would be appreciated.
>>
>> dixie[/color]
> --
> regards,
>
> Bradley
>
> A Christian Response
> http://www.pastornet.net.au/response
>[/color]


Br@dley
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Altering tables in code


Dixie <dixie@dogmail.com> wrote:[color=blue]
> Had a quick look at the help file, but it is mainly about creating new
> tabledef objects and I don't want to iterate through the tabledef
> collection.
>
> Say there was already a table in the database called 'MyTable' and I
> wanted to add a field called MyNewField and then say set it as a text
> field of 25 characters. How do I do that in code.
>
> dixie[/color]

You don't need to iterate through the collection...

eg. CurrentDB.TableDefs("tblMyTable").Fields("myField" )
[color=blue]
> "Br@dley" <n0mail@4u.com> wrote in message
> news:Penye.14792$oJ.7716@news-server.bigpond.net.au...[color=green]
>> Dixie <dixie@dogmail.com> wrote:[color=darkred]
>>> I wish to be able to do some things to tables in code.
>>>
>>> 1. Add a field and its properties.
>>> 2. Alter the properties of an existing field in a table.[/color]
>>
>> Lookup the help on the Tabledef oject.
>>[color=darkred]
>>> 3. Append some extra entries onto the bottom of a table, if they are
>>> not already there.[/color]
>>
>> Search for the record. If it doesn't exist then add it.
>>
>> eg. (very simplified DAO example)
>>
>> myRS.FindNext "[myID] = 1"
>> If myRS.NoMatch then
>> myRS.AddNew
>> myRS![myID] = 1
>> myRS.Update
>> End If
>>[color=darkred]
>>> Any help would be appreciated.
>>>
>>> dixie[/color]
>> --
>> regards,
>>
>> Bradley
>>
>> A Christian Response
>> http://www.pastornet.net.au/response[/color][/color]

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


rkc
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Altering tables in code


Dixie wrote:[color=blue]
> Had a quick look at the help file, but it is mainly about creating new
> tabledef objects and I don't want to iterate through the tabledef
> collection.
>
> Say there was already a table in the database called 'MyTable' and I wanted
> to add a field called MyNewField and then say set it as a text field of 25
> characters. How do I do that in code.[/color]

CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25")
Closed Thread