473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Possible to write a macro that creates a new table?

Hello,

Is it possible to write/record a macro in Access that would create a new table?

The new table's name would be assigned based on the current value in one of the combo boxes in the form, and the new table would only need to be one column.

Thanks!
Feb 15 '08 #1
7 10927
MindBender77
234 100+
Hello,

Is it possible to write/record a macro in Access that would create a new table?

The new table's name would be assigned based on the current value in one of the combo boxes in the form, and the new table would only need to be one column.

Thanks!
I believe what you are asking could be done using a "MakeTable Query".

Bender
Feb 15 '08 #2
thanks..perhaps I was unclear in my original post...

I want to have, let's say, a button on a form that, when clicked, creates and opens a new table that is named after the active selection in a combo box that is also on this form.
Feb 15 '08 #3
just wondering if anyone has any ideas for me, please!
Feb 18 '08 #4
FishVal
2,653 Expert 2GB
Hi, there.

You may use
  • SQL: either SELECT ... INTO (to create table using query as a template) or CREATE TABLE (to create table from scratch)
  • VBA: TableDefs collection (somewhat more sophisticated technique)

Just out of curiosity, what a very special reason you have to create tables with button clicks?

Regards,
Fish
Feb 18 '08 #5
ADezii
8,834 Expert 8TB
just wondering if anyone has any ideas for me, please!
Yes, it can be done, and here is perhaps the simplest Method. I'll post it, but I'm with FishVal on this one, just wandering why you would want to do this.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyTable As DAO.TableDef, MyField As DAO.Field
  2.  
  3. If IsNull(Me!cboTableNames) Then Exit Sub
  4.  
  5. Set MyDB = CurrentDb()
  6.  
  7. 'Create a Table based on the Combo Box (cboTableNames) selection
  8. Set MyTable = MyDB.CreateTableDef(Me!cboTableNames)
  9.  
  10. 'Create a Field named Field1 , Text Data Type, Size 255
  11. Set MyField = MyTable.CreateField("Field1", dbText, 255)
  12.  
  13. 'Append the Field to the Fields Collection of the Table
  14. MyTable.Fields.Append MyField
  15.  
  16. 'Append the Table  to the Tabledefs Collection of the Database
  17. MyDB.TableDefs.Append MyTable
  18.  
  19. 'Refresh to TableDefs Collection
  20. MyDB.TableDefs.Refresh
Feb 19 '08 #6
thank you for the help! I will give this a try and see if I can get it to work (I'm new to the coding, but I think I can struggle with it long enough to make it happen).

here is the application, which you were asking about:

our office has to complete certain tasks on individuals who have responded to an invitation. normally, we have to manually screen each responder to see if they meet the criteria that warrants action on our part. I have designed a simple form-based tool with one fields and a button.

The first field is a combo box that is populated with all of the active events. The user selects the event on which they are working and presses the submit button which opens a run-query macro and returns a list of responded invitees requiring action. Very simple tool, saves a lot of time.

The new feature that I'm trying (with this post) to implement is this: I'd like to make it possible for the user to enter the ID numbers of the invitees for which action has already been taken - sort of a checklist of who they've already done. This list of completed IDs would then be omitted from the results the next time someone select an event and runs the query. I figured that by having a table of completed IDs, that table could be worked into the query/macro in a way that would omit those from the results.

I'm sure there must be a more elegant way to do this (and I'm open to your ideas), but this was one idea I had.

Thank you!!
Feb 19 '08 #7
Scott Price
1,384 Expert 1GB
A more elegant approach ( and one conforming to Database Normalisation Rules ) would be to include a field in your existing table that holds Completed Yes/No data.

Then your query could simply exclude those entries that are marked as Completed Yes by a simple WHERE [tableX].[CompletedField] = No criteria statement.

Regards,
Scott
Feb 19 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bon | last post by:
Hello all Would it be possible to migrate the MS Access 2000 to MS SQL Server 2000? My application is using MS Access 2000 as database and as user interface such as forms. Now, I want to...
1
by: Deano | last post by:
Hi, I need to disable a command button at some point. Easy enough. Initially in design view it is set as enabled. Now once I disable it, how can I ensure that when the app is restarted, the...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
8
by: Thorsten Ottosen | last post by:
Dear all, I'm new to C#, so forgive my stupid question. In my question to avoid boilerplate code, I was wondering if I could use attributes to generate some code for me. For example ...
7
by: fei.liu | last post by:
#define ONCFILE_ERR1(funcname, name) \ { \ #ifdef DEBUG\ cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " << funcname << " " << name << endl; \ #endif \ } I want to have...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
5
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
0
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined...
3
by: thinktwice | last post by:
i want to define a macro like #define STRING2(x) #x #define STRING(x) STRING2(x) #define PROMPT(x) #pragma message(__FILE__ "(" STRING(__LINE__) "):" STRING(x)) <---- compile failed i...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.