Results 1 to 2 of 2
  1. #1
    Dinzdale40 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    12

    MakeTable Query with Variable user defined Name

    I need to figure out how to have a make table query run that asks the user for the name. It is making a table in another database for a different purpose and so it important that the table name change every month. I am trying to keep it so that if the table from the first month doesn't get used it will not be overwritten next month.



    I've done this kind of thing before but I had the make table queries using a set name creating an excel file that was later taken via vba and formatted/resaved to my variable user defined file name.

    Any help would be most appreciated. I was thinking there was some way to put the sql into VB, but am unsure of how to use the variables if i do that.

    Here is an example of my sql for the make table query.

    SELECT [Current Month].ID, [Current Month].[Period Ending], [Current Month].[Prj CC], [Current Month].SAC, [Current Month].[Project #], [Current Month].[CIP #], [Current Month].[Project Description], [Current Month].[Task Phase], [Current Month].[Task Name], [Current Month].[Total Hrs], [Current Month].[EST Cmp Date], [Current Month].[Bus Unit] INTO 2011_02 IN 'F:\Ref\Test\TargetDB.accdb'FROM [Current Month];

  2. #2
    Dinzdale40 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    12
    This worked. Figure I would post it here if anyone else needed it.

    Code:
     
    Private Sub Command0_Click()
     
    Dim strSQL As String
    Dim varYearMonth As Variant
     
    varYearMonth = InputBox("Enter Table Name YYYY_MM")
    If varYearMonth = "" Then Exit Sub
     
    strSQL = "SELECT [Current Month].ID, [Current Month].[Period Ending], [Current Month].[Prj CC], [Current Month].SAC, [Current Month].[Project #], [Current Month].[CIP #], [Current Month].[Project Description], [Current Month].[Emp CC], [Current Month].[Task Phase], [Current Month].[Task Name], [Current Month].[Total Hrs], [Current Month].[EST Cmp Date], [Current Month].[Bus Unit], [Current Month].Discretionary, [Current Month].Month, [Current Month].[Project Class] INTO " & varYearMonth & " IN 'F:\Ref\Test\TargetDB.accdb' FROM [Current Month];"
    
    DoCmd.RunSQL strSQL
     
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-07-2010, 04:22 PM
  2. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM
  3. How to add user-defined ribbon in access 2007
    By ali-gagi in forum Access
    Replies: 1
    Last Post: 07-02-2009, 07:01 AM
  4. Replies: 23
    Last Post: 03-26-2009, 06:50 PM
  5. Possible to store user-defined types in table?
    By Binky in forum Programming
    Replies: 0
    Last Post: 11-20-2008, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums