Results 1 to 2 of 2
  1. #1
    Kivan is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    27

    Custom table name

    I've created a query which copies a table. The thing is I want to choose table name everytime I use this query. So i want the table name not to be defined but to be chosen by user everytime he runs query. Is there any way of putting a parameter into the table name? I'm very beginner with Access so the easiest solutions will be welcome .



    regards

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The only way I can think of is to use a Form where the user can enter/select the name of the table they wish to copy, then using VBA write the SQL code for the query to copy that table.

    If you create an example of your Make Table Query in Query Builder, if you switch to SQL view, this will show you the structure of the SQL code that you will need to build in VBA.

    I created a simple form with three objects:
    - A text box for entering in the name of the table you want to copy (I named it txtFromTable)
    - A text box for entering in the new name of the table you are creating (I named it txtToTable)
    - A command button to click to perform the copy

    Here is what the code behind the Click event of my command button looks like.
    Code:
    Private Sub cmdCopyTable_Click()
        Dim mySQL As String
        
    '   Verify there are entries in both fields
        If IsNull(txtFromTable) Or IsNull(Me.txtToTable) Then
            MsgBox "Missing table name entry!", vbOKOnly, "COPY CANCELLED!!!"
            Exit Sub
        End If
            
    '   Build SQL code to copy table
        mySQL = "SELECT [" & Me.txtFromTable & "].* " & _
                "INTO [" & Me.txtToTable & "] " & _
                "FROM [" & Me.txtFromTable & "];"
        
    '   Run SQL code to copy table
        DoCmd.RunSQL mySQL
        
    End Sub

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

Similar Threads

  1. Replies: 7
    Last Post: 04-16-2012, 03:31 PM
  2. Replies: 3
    Last Post: 03-31-2012, 05:21 PM
  3. Replies: 1
    Last Post: 03-25-2012, 01:53 PM
  4. Custom Functions
    By TheDeceived in forum Access
    Replies: 3
    Last Post: 09-16-2010, 02:12 PM
  5. Custom MsgBox
    By roccoIT in forum Programming
    Replies: 3
    Last Post: 07-06-2010, 10:43 AM

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