By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

Possible to write a macro that creates a new table?

P: 27
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
Share this Question
Share on Google+
7 Replies


MindBender77
100+
P: 234
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

P: 27
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

P: 27
just wondering if anyone has any ideas for me, please!
Feb 18 '08 #4

FishVal
Expert 2.5K+
P: 2,653
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
Expert 5K+
P: 8,701
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

P: 27
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
Expert 100+
P: 1,384
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

Post your reply

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