Results 1 to 5 of 5
  1. #1
    RangerJeff is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2020
    Posts
    10

    auto creating records on subform

    Hi
    New to Access, so still learning.
    I have a main form (table) called Permits with a start_date and end_date. I have a subform (table) called Permit_locations with a one to many relationship to Permits. After I enter the dates on the Permit form, I want to generate the number of records on the subform (Permit-locations) (= to End_date-Start_date), with the date field filled out for each record on the subform, basically one for each day.

    I create a field in the main table called STAYS which is a calculated field of end_ date - start_date,. So I was thinking doing an After_Update event when end date is entered and have it create the records in the subform/Permit_location table.

    May I am just missing it, but don't see the commands I would need for my VBA script. I have no problems creating individual records in the subform, but have to enter all the data manually. There is no limits on the number of nights but generally it is not more than 14.

    Here is a picture of the subform
    Click image for larger version. 

Name:	Permit_locations.jpg 
Views:	21 
Size:	25.6 KB 
ID:	42792



    All help will be appreciated

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You post isn't real clear (e.g. = to End_date-Start_date). Something is equal to end date minus start date? End date to start date? And what equals those/that?
    If end minus start gives you some record count (e.g. 6 days = 6 records needed) then I think you'll have to create a loop with that result as your counter, then add a record to a DAO recordset you created based on the form recordsource by appending to at least one field for each loop. When done, you requery the form.

    Not sure if I understand the requirements so that's my take for now.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    If Start_Date = 8/1/2020...End_Date = 8/5/2020

    you want, in the Subform, you want to generate 5 Records, dated

    8/1/2020
    8/2/2020
    8/3/2020
    8/4/2020
    8/5/2020

    Is that the idea?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    RangerJeff is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2020
    Posts
    10
    Thanks, I should have realized a simple loop. Now I just need to figure out how to add records in the subform, since the user will have to enter more data.

  5. #5
    RangerJeff is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2020
    Posts
    10
    yes. I want to gnerate 5 records in the related (child) table which is in the subform and increment the date for each record. The user will have to add other information.
    Do either a loop in the main form, or when I enter the subform, it could generate the records then. All the examples I can find online and in the books seem to want you to open the db but it is already open.

    I guess I am expect too much ease of use from ACCESS. I am having trouble of how to use the fields in a table to assign a value to a variba]ble in the VBA script. Not sure of the format.

    THis should be simple. TO many years of mainframe stuff I guess.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-14-2018, 08:15 PM
  2. Replies: 20
    Last Post: 06-16-2018, 12:36 PM
  3. Table within a subform creating new unwated records
    By Snickren in forum Database Design
    Replies: 2
    Last Post: 03-27-2018, 01:01 PM
  4. Replies: 4
    Last Post: 06-18-2012, 07:01 AM
  5. Replies: 12
    Last Post: 08-30-2011, 03:36 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