Possible to write a macro that creates a new table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seagullino
    New Member
    • Jun 2007
    • 27

    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!
  • MindBender77
    New Member
    • Jul 2007
    • 233

    #2
    Originally posted by seagullino
    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

    Comment

    • seagullino
      New Member
      • Jun 2007
      • 27

      #3
      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.

      Comment

      • seagullino
        New Member
        • Jun 2007
        • 27

        #4
        just wondering if anyone has any ideas for me, please!

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          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

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by seagullino
            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.
            [CODE=vb]
            Dim MyDB As DAO.Database, MyTable As DAO.TableDef, MyField As DAO.Field

            If IsNull(Me!cboTa bleNames) Then Exit Sub

            Set MyDB = CurrentDb()

            'Create a Table based on the Combo Box (cboTableNames) selection
            Set MyTable = MyDB.CreateTabl eDef(Me!cboTabl eNames)

            'Create a Field named Field1 , Text Data Type, Size 255
            Set MyField = MyTable.CreateF ield("Field1", dbText, 255)

            'Append the Field to the Fields Collection of the Table
            MyTable.Fields. Append MyField

            'Append the Table to the Tabledefs Collection of the Database
            MyDB.TableDefs. Append MyTable

            'Refresh to TableDefs Collection
            MyDB.TableDefs. Refresh[/CODE]

            Comment

            • seagullino
              New Member
              • Jun 2007
              • 27

              #7
              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!!

              Comment

              • Scott Price
                Recognized Expert Top Contributor
                • Jul 2007
                • 1384

                #8
                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

                Comment

                Working...