Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    26

    Create a new entry based on old one

    Hello,
    This should be fairly simple, but I can't seem to finish off the code for this to work. I've followed other posts to do what I want to do, but I cant seem to get it going.

    I have a form with a subform with a button beside. If a user presses the button, a new entry in the table (the source of the subform) will be created with the exact same entries as the selected record. The small code I wrote is an SQL Query that does INSERT on a SELECT. It works, but I cannot seem to restrict to the selected record without getting a "Too few parameters" Error.



    Here is the code of the button:
    Code:
    Private Sub Command5_Click()

    CurrentDb.Execute ("INSERT INTO tblTestTable (TestAttribute1, TestAttribute2, TestAttribute3)" _
    "SELECT TestAttribute1, TestAttribute2, TestAttribute3 FROM tblTestTable WHERE (((tblTestTable.TestID)=(Me.tblTestTable_subform_Label![TestID])));")
    Me.Refresh

    End Sub 
    Any help would be appreciated, thx. I uploaded a sample database with the code that is not working.

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Use this for your function:

    Code:
    CurrentDb.Execute ("INSERT INTO tblTestTable (TestAttribute1, TestAttribute2, TestAttribute3)" & _
    "SELECT TestAttribute1, TestAttribute2, TestAttribute3 FROM tblTestTable WHERE (((tblTestTable.TestID)=(" & Me.tblTestTable_subform.Form.[TestID] & ")));")

  3. #3
    Join Date
    Jul 2010
    Posts
    26
    Wow. You don't know how much time I've wasted. A million thanks.

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    My pleasure.

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

Similar Threads

  1. Replies: 6
    Last Post: 10-22-2022, 08:27 AM
  2. Limit data entry based on another field
    By chemengr in forum Forms
    Replies: 5
    Last Post: 01-02-2014, 01:21 PM
  3. Create a report based on a pop-up form
    By p4ck3tl055 in forum Reports
    Replies: 1
    Last Post: 03-29-2010, 09:38 AM
  4. Replies: 3
    Last Post: 02-17-2010, 02:29 PM
  5. How to create and print unique report for each entry???
    By Stelios Panayides in forum Reports
    Replies: 2
    Last Post: 10-05-2009, 08:54 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