Results 1 to 8 of 8
  1. #1
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29

    Adding new partial records to a subform

    I'm trying to figure out how to add a record to a continuous subform from another subform and partially fill in the data and have the user fill in the rest. Is this possible?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Any number of ways, depending on your specifics. One would be executing an append query and requerying the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Thanks for your response. That makes a whole lot of sense. I spent too much time try to set the texboxes to the value I wanted and got frustrated.

    Is there a way I could select one textbox in the last record of a continuous subform? I seem to be having issues correctly referencing continuous controls from the main form.
    Last edited by DarkWolff; 03-06-2012 at 02:39 PM.

  4. #4
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Ok I have the append query partially working. However, it run I run the code it tries to add 374 duplicates of the record. Here is the SQL code:

    INSERT INTO tblNYTimesheet_Monthly ( StaffID, [month], [Project#], FiscalYear, hours )
    SELECT [Forms]![frmTimesheet_Monthly]![txtStaffID] AS StaffID, [Forms]![frmTimesheet_Monthly]![txtmonth] AS [month], [Forms]![frmTimesheet_Monthly]![fsubTSResAlloc]![txtProjectID] AS [Project#], [Forms]![frmTimesheet_Monthly]![txtCurrentFY] AS FiscalYear, 0 AS hours
    FROM tblNYTimesheet_Monthly;

    The code is run from a command button on a continuous subform (so it knows the correct record). I have no idea where the 374 comes from though.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Without a WHERE clause, the SELECT will pull every record in the table. I assume there are currently 374. You want a criteria on the key field that points to the form to restrict it to that record. In SQL view that would look something like:

    INSERT INTO tblNYTimesheet_Monthly ( StaffID, [month], [Project#], FiscalYear, hours )
    SELECT [Forms]![frmTimesheet_Monthly]![txtStaffID] AS StaffID, [Forms]![frmTimesheet_Monthly]![txtmonth] AS [month], [Forms]![frmTimesheet_Monthly]![fsubTSResAlloc]![txtProjectID] AS [Project#], [Forms]![frmTimesheet_Monthly]![txtCurrentFY] AS FiscalYear, 0 AS hours
    FROM tblNYTimesheet_Monthly
    WHERE KeyFieldName = [Forms]![frmTimesheet_Monthly]![fsubTSResAlloc]![KeyFieldName]

    Using the correct field/control names of course.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Oh, you could also use VALUES instead of SELECT:

    INSERT INTO tblNYTimesheet_Monthly ( StaffID, [month], [Project#], FiscalYear, hours )
    VALUES( [Forms]![frmTimesheet_Monthly]![txtStaffID], [Forms]![frmTimesheet_Monthly]![txtmonth], [Forms]![frmTimesheet_Monthly]![fsubTSResAlloc]![txtProjectID], [Forms]![frmTimesheet_Monthly]![txtCurrentFY], 0 )

    A VALUES clause will only insert a single record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    DarkWolff is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    29
    Thank you! That did it!

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Adding Records in a Subform
    By chris.williams in forum Forms
    Replies: 3
    Last Post: 10-14-2011, 01:21 PM
  2. Adding totals to a form from a subform
    By Niki in forum Access
    Replies: 13
    Last Post: 05-13-2011, 12:17 AM
  3. Replies: 10
    Last Post: 01-10-2011, 07:52 PM
  4. After adding data on subform
    By Nancy in forum Forms
    Replies: 9
    Last Post: 12-22-2010, 06:19 PM
  5. Adding multiple records in subform
    By randolphoralph in forum Programming
    Replies: 1
    Last Post: 05-12-2010, 09:42 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