Results 1 to 10 of 10
  1. #1
    S1naps1s is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    8

    Create records between 2 dates

    Is it possible to define 2 dates and create a record for each day in between? I am creating a "sick occurence" database. I want to define the first day the individual calls off sick and the day they will return, then calculate how many sick days they will be using. However, I need to take into consideration any relief days or assigned time off.
    Basically, I want to be able to assign what is going on everyday between these 2 defined dates. Be it, holiday, annual leave, personal leave, sick leave, or regular relief. If further clarification is needed, I can go more in depth. Thanks in advance for any help!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, you can use VBA to get the start date and end date, then loop to create (insert/append) the required number of records into the table.
    Do the math to determine the number of loops required.


    And welcome to the forum...

  3. #3
    S1naps1s is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    8
    Awesome! Thanks, I wondered if I could do that. Here's my issue, I have tried to do loops before, to no avail. Where can I go to get good info on loops? Or can someone tell me the correct way to do them?

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Many things are needed to understand your qualifications and schema. Company Policy, Absence Policy, etc...
    Example: Days:
    DateDiff("d",[abscenceDtefrom],[AbscenceDteTo])
    HTH

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Someplace you should have two unbound controls to enter the start date and the end date.
    In (pseudo) code:

    This is a FOR...NEXT loop. There are many types of loops.
    Code:
      declare variables
      read the value from the start date control
      read the value from the end date control
      subtract the dates (use the DateDiff() function)
    
    'This gives the number of times to loop.
    
    assign  startdate to a variable
    For i = 1 to NumDaysToLoop
    
          INSERT SQL statement - need to add required data EmpID, Start & end date
    
        increment the date variable by 1 (DateAdd() function)
    
    Next

    Where can I go to get good info on loops?
    Google "for next loops VBA"

    Here is one: http://ms-access-tips.blogspot.com/2...-learning.html

  6. #6
    S1naps1s is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    8
    Okay, thanks for the awesome advice, it worked, FLAWLESSLY!!!!!
    I do have one additional problem though. Basically all I enter is the start date of the occurrence and the return to work date, from there, VBA does the math for me. I have it immediately put it into the table. So here is my problem, if there is a problem noticed (put in the wrong return to work date or something of the sorts) and the user presses the "calculate" button, it adds a whole new set of records, duplicate though. Is there a way that I can put the data into a "temporary" table and when I press "complete" it puts all the info into the "official" table? That way if I re-compute or cancel the request, there aren't duplicate entries?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Using an intermediate 'temp' table won't prevent the duplication. Options:

    1. set compound index so Access won't allow duplication and will popup warning to user if they attempt to commit duplicate records

    2. code to validate the entries - to check the table for existing records before committing new records
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    S1naps1s is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    8
    So, I guess I'm thinking on compute onclick, do a dcount if it is greater than 1, then don't allow addition? That's kind of what I'm thinking. Probably the easiest. Any other suggestions?
    Now, when I do this, is there a way that I can overwrite rather than not allowing? Almost like, when I copy and paste and there is already a file of the same name there. Can I have the option to overwrite or not allow the change? I'm thinking of how I can best word these questions. It's such an odd problem.

  9. #9
    S1naps1s is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    8
    Okay, nevermind, the composite index is DEFINITELY easier. However, now, regarding the ability to overwrite rather than duplicating or being stuck with the results I've previously entered. Can THIS be done?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    You can run DELETE or UPDATE sql actions.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. REcords between certain dates
    By stenman in forum Queries
    Replies: 2
    Last Post: 09-12-2013, 08:31 AM
  2. Replies: 2
    Last Post: 05-28-2013, 04:00 PM
  3. Replies: 1
    Last Post: 02-16-2013, 11:36 AM
  4. Looking for overlap in dates between two records
    By kagoodwin13 in forum Queries
    Replies: 4
    Last Post: 03-09-2012, 12:37 PM
  5. Replies: 3
    Last Post: 07-10-2011, 05:37 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