|
-
May 29th, 2008, 09:00 AM
#1
Thread Starter
New Member
Automatically creating new fields in Access using Macros
Hi,
I am relatively new to Access so play nice...
I have a requirement to import regular data into Access and then do a series of queries on the data. I have got quite a long way with it but I am stuck on the following;
I need to add some fields to a table (PageExtent, Runcode and MailsortTrigger) and then populate these fields with data. I can't find any other way apart from manually adding the fields to the table first then running the update queries as individual queries. Is there a better way of doing this?
Thanks in advance...
Richard
UPDATE table SET PageExtent = "E18";
UPDATE table SET RunCode = "testR";
UPDATE table SET table.MailsortTrigger = "0";
-
May 29th, 2008, 01:37 PM
#2
Frenzied Member
Re: Automatically creating new fields in Access using Macros
Hi. Welcome to the forum.
You can create a Data Definition query:
Code:
ALTER TABLE theTable
ADD PageExtent TEXT(20),
RunCode TEXT(20),
MailSortTrigger SMALLINT;
and populate it in one update query like this:
Code:
UPDATE theTable
SET PageExtent = "E18", RunCode = "testR", MailSortTrigger = 0
WHERE theKey = "something";
I'm not sure why you need to add columns dynamically at run-time though. That doesn't necessarily sound like the best solution. Can you tell us any more about what you are trying to achieve?
-
May 29th, 2008, 10:21 PM
#3
Re: Automatically creating new fields in Access using Macros
DDL have implicit COMMIT, it's not advisable to mix DML and DDL.
-
May 29th, 2008, 10:54 PM
#4
Re: Automatically creating new fields in Access using Macros
If its only the 3 fields then it would be better to manually create them as you dont want it to run in a macro possibly a second time etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|