Results 1 to 3 of 3
  1. #1
    ser01 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    64

    Changing select query to append query with VBA

    I have a select query that uses a criteria to select some records and puts them in a table for the user to modify them. The SQL for the query is being changed with VBA when the form is launched because the criteria is dynamic Once it is done being changed i would like to be able to put the records in a different table than the one the records came from. The only way to do that (than i seem to think of) is to use VBA and change the SQL of the query making it an append query. So this query would be changed back and forth in VBA. Is this the right way to do this and common practice or do I need to look for a different solution?

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Let me get this straight you have a select query which you use to populate a form. You want to use the return values of the same query to insert into another table using an insert query.

    I have two simple tables
    Give={ID,A,B}
    Take={ID,A,B}

    I have used a command button to insert the result of a select query into Table Take from Table Give. Here is the code.

    Private Sub Command0_Click()
    Dim strSQLInsert As String
    strSQLInsert = "Insert Into take (ID,A,B) SELECT ID,A,B FROM Give WHERE ID = 1"
    DoCmd.RunSQL strSQLInsert
    End Sub

    So now you can use the same select query to get the values for an Append query and insert the record in your table.

    If this solves your problem please mark this thread solved.

  3. #3
    blah is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    2

    how about reading the question, Einstein?

    Quote Originally Posted by maximus View Post
    Let me get this straight you have a select query which you use to populate a form. You want to use the return values of the same query to insert into another table using an insert query.

    I have two simple tables
    Give={ID,A,B}
    Take={ID,A,B}

    I have used a command button to insert the result of a select query into Table Take from Table Give. Here is the code.

    Private Sub Command0_Click()
    Dim strSQLInsert As String
    strSQLInsert = "Insert Into take (ID,A,B) SELECT ID,A,B FROM Give WHERE ID = 1"
    DoCmd.RunSQL strSQLInsert
    End Sub

    So now you can use the same select query to get the values for an Append query and insert the record in your table.

    If this solves your problem please mark this thread solved.
    He didn't ask (and I didn't google) how to insert records. He asked how to programatically change a query from "select" to "append."

    Completely different animals, comprende?

    OP: given the way the query designer works, one would think this is a property that you could edit and therefore have the sql changed automatically BUT I'm afraid I'm on the same hunt as you. Gluck.

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

Similar Threads

  1. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 AM
  2. Append Query
    By aabh in forum Queries
    Replies: 6
    Last Post: 02-02-2010, 04:26 PM
  3. Append Query
    By cotri in forum Queries
    Replies: 1
    Last Post: 01-28-2010, 08:52 PM
  4. Control Value Select Append
    By NinjasVsPirates in forum Programming
    Replies: 0
    Last Post: 08-18-2009, 10:42 AM
  5. Changing Query on the Fly
    By pdouglas in forum Programming
    Replies: 0
    Last Post: 06-25-2009, 10:58 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