Add a field to a table and fill it

oliver_penney

Board Regular
Joined
Dec 18, 2002
Messages
182
hi

this is probably dead easy, but i'm sick of wading throught the help file :)

in VBA, how do i add a field to a table, name it "xxx" and fill it with "yyy"

"yyy" is the same for all records, so that should make it easier

thanx in advance

ol
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Do you need to store the 'yyy'?

Probably not.

I would use a query,

Make a new query, insert your table and fields you need, then add a new field like this:
XXX: "YYY"
and it will fill down for every record.
The SQL is as follows:
SELECT TblOliver.ID, TblOliver.Field1, "YYY" AS XXX
FROM TblOliver;

Replace TblOliver with your table name and Field1 with your field(s) name(s).

This is a better method than storing the "YYY" because it uses no memory.

If you absolutely need to store the "YYY"s in a table, add a field to TblOliver (or whatever you call it), and call the field "XXX", and make it a 3 character text field.

Now, use SQL as follows to add "YYY" to each record in this table.
UPDATE TblOliver SET TblOliver.XXX = "YYY";

HTH,
 
Upvote 0
i got it in the end, i used something like your second method

it was more complicated than "YYY" in each table, essentially i was populating the field with the table name, so that when i UNIONed all of them together i could tell where they came from

i used CreatField and then i used a update bit of SQL

*phew*

thanx
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,359
Members
451,642
Latest member
mirofa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top