Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert a field into a table within a maco

Status
Not open for further replies.

keusch

Technical User
Jun 17, 2001
41
US
Within a macro, I need to insert a new field name in a existing table.
For this part of the macro I am using commands:
Action OpenTable (TableName, View Design, Add)
Action RunCommand InsertRows

Here's my problem:
I want to go to the bottom of the table to insert the row
And I want to call the new Field: summary_data
I can't seem to figure it out. After that queries are launched to populate and check the data.
HELP. I can't find it in the help screens.
 
keusch ,

I have not used macros in my apps, but use a module to add new fields, modify field properties, and establish relationships. I call the module first and if the new field does not exist the code to add it runs. That way when the user opens tha app the changes are made.

I use alter table and crate index and the new field is automatically the last field in the database design list.

The Acess help is pretty good.

Jdemmer
 
Hi.

There are 2 ways around this.

1.

1.1. Create a query to add the field to the table

alter table tablename add column summary_data memo

make sure that you give the query a relative name eg.add_column_summdata

(Nb. here I am guessing that the type of field that you want to add is a memo field)

1.2. From the macro use :

action OpenQuery (set the query name to the query that you wrote in 1.1. eg.add_column_summdata)

1.3. Run the macro.

2. Write the code to create the field (bung it in a global module function) :

e.g. Public Function AddSummDatField() as boolean

Dbengine.workspaces(0).databases(0).execute("alter table tablename add column summary_data memo")

End Function

2.2. Now use the "RunCode" action from the macro, and call AddSummDatField


'---------------------------

Both these will work, its up to you which you choose. The advantage of the second over the first is that :

1. You don't create a new query (safer)
2. You could change the arguments that it takes, so you could call it and pass the name of the table to amend :

e.g. Public Function AddSummDatField(Byval tablename as string) as boolean

Dbengine.workspaces(0).databases(0).execute("alter table " & tablename & " add column summary_data memo")

End Function

Dont worry about the function not returning anything. The system doesn't mind either!

Regards,
Mr Big.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top