Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Check For Records From Date Every 7 Days

    I need to figure out a way to take my date and from there count 7 days and keep counting from the last 7 day date. (EventStart) a field in my table (Date Field) is the starting date of the transaction and from there count 7 days and from that date count 7 days and keep on until date is now. Can this be done in vba or does it have to be a module? dteentered is the date it is supposed to be entered on or was entered on. If it was entered dteentered will shows that date.

    Okay, found this code, trying to modify! My field in tblEvent is named dteentered
    code below is cold fusion but it is what I am after:

    <cfset startDate = dteentered>
    <cfset endDate = Now()
    <cfloop from="#startDate#" to="#endDate#" index="i" step="#CreateTimeSpan(7,0,0,0)#">
    <cfoutput>#dateformat(i, "mm/dd/yyyy")#<br /></cfoutput>


    </cfloop>
    __________________________________________________ ______
    I know this is wrong but it is the best I can do with my limited knowledge.
    Public Sub byseven() 'Purpose: Find Dates in Increments of 7 Using EventStart Field in tblmissedtransactions.
    Dim db As DAO.Database 'Check if date is in field dteentered and if so, increment 7 days from there.
    Dim strSQL As String 'Starting date was EventStart, next date entered is dteentered.
    Dim rs As ADODB.Recordset
    Dim byseven As Date
    Set db = CurrentDb ()


    rs.Open "tblmissedtransactions", CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'Open the ADO recordset.
    byseven = rs!EventStart

    rs!byseven = byseven + 7
    byseven = rs!byseven
    rs.Update
    Set rs = Nothing
    Last edited by burrina; 02-07-2013 at 02:03 PM. Reason: new code again.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Very confusing.

    Is there only one record in tblmissedtransactions that has a date for EventStart field?

    You are mixing DAO with ADO....

    While you can add to a date using this syntax: byseven + 7 , I always use the DateAdd() function:
    rs!byseven = DateAdd("d",7,byseven)

    Do you want to add only 7 days or add multiple 7 day increments? (per the Cold Fusion code)
    Would you give an example of what you want using actual dates?


    If EventStart = 10/2/2012 then ...........

    Add only 7 days??
    Or ?????


    10/2/2012
    10/9/2012
    10/16/2012
    10/23/2012
    ......

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Advance by Increments of 7 Days

    There are lots of records in that table and all have a date for EventStart. They would not be a record without it.
    Actual date: Pic attached. If a event or record has a date of 1/24/2013 (EventStart) with a EventID of 23 (Primary Key) and is supposed to entered again on 1/31 and every 7 days after that. So the field dteentered becomes the next date it is supposed to be entered. EventStart is just the original start date. So from dteentered (date field) onward every 7 days it should get entered. dteentered is the actual date it is entered even from the very first EventStart. After the first record is entered dteentered is used since EventStart will not get modified again.
    Attached Thumbnails Attached Thumbnails tblmissedtransactions.jpg  

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Forgive me, but I don't see a field "EventStart".

    Date fields I see:
    TransDate
    MyDte
    dteentered
    Date Edited. (with a space and period?)



    Would you change the date for only one record for EventID of 23 or all records for EventID of 23?

    (Obviously not walking with you yet )

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Sorry, you can't see EventID because the pic does not scroll over far enough. I would have to change the dates in this instance of all records that met the criteria of being a recurring event but was not entered when the 7 day period came around. These are missed transactions, meaning that they were supposed to be entered when the scheduled date came but were not. Since they have not been entered with a 7 day period, they will be deleted. Some of these dates, i.e. records have not expired and so will not get deleted. There are a lot of other factors and things that affect this but I am trying to keep this simple and not confuse anyone. It is complex. That is why i just want to keep to this one scenario! I am sure most everyone on here is smarter than me and has more experience but even so this is a complex db. Can this be done with vba or would a module be best? I do not have any experience with modules other than some light editing.

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Monthly Missed Transactions Example

    Here is a screenshot of Missed Monthly Transactions. Notice how many and the dates. I would want to see ONLY those transactions that are every 30 days right? This table of missed events shows ALL the dates a transaction was missed all the time. On my form with the linked subform it is automatically filtered by type of transaction, menaing you ONLY see the type of transaction for that record. if you are looking at a monthly transaction on the main form, you see only monthly missed transactions on the subform. I run a delete query to get rid of all entered transactions in the missed transactions table and all entered transactions so the list gets smaller. There are right now 13 records in the table tblmissedtransactions for the Monthly transactions. The first entered transaction was on the 1/24/2013 and then every 30 days from then on.So, NONE of those dates, i.e. transactions qualify and have to be deleted.Just a example of a missed transaction. Here is a view of the scheduler showing the same thing.Notice the EventID, EventStart Date, next scheduled date and then look at the missed events subform, there are 13 missed transactions, but not really since they dont qualify.
    Attached Thumbnails Attached Thumbnails monthlymissedtransactions.jpg   scheduler.jpg  
    Last edited by burrina; 02-08-2013 at 09:23 AM. Reason: Scheduler Screenshot

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It is complex.
    Yes, I've watch as you've asked some interesting questions.

    Can this be done with VBA or would a module be best?
    Modules contain VBA code. There are 3 types of modules:
    Class Modules: for more advanced code. I don't/haven't use this module yet.
    Form Modules: VBA code for a form that is available to only that form. AKA "code behind a form"
    Standard Modules: (referred to as a Module) VBA code that is available to the whole project.

    Wasn't sure if you wanted ALL records in tblmissedtransactions updated or only selected records (by EventID?)
    I opted for all records......
    Code:
    Public Sub byseven()
       'Purpose: Find Dates in Increments of 7 Using EventStart Field in tblmissedtransactions.
       'Check if date is in field dteentered and if so, increment 7 days from there.
       'Starting date was EventStart, next date entered is dteentered.
    
       Dim db As DAO.Database
       Dim strSQL As String
       Dim rs As DAO.Recordset
       Dim byseven As Date
       Dim Event_ID As Long
    
       Set db = CurrentDb()
    
    
       Event_ID = Me.EventID   ' or Event_ID= Forms!FormName.EventID
    
       'Get the date
       Set rs = db.OpenRecordset("tblmissedtransactions")
       If rs.BOF And rs.EOF Then
          MsgBox "No records"
       Else
          byseven = rs!EventStart
          byseven = DateAdd("d", 7, byseven)
    
    '----------------------------------------
          'Update dteentered - With criteria
    '      strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & byseven & "#"
    '      strSQL = strSQL & " WHERE tblmissedtransactions.dteentered = " & Event_ID & " ;"
    '----------------------------------------
    
          'Update dteentered - all records in tblmissedtransactions
          strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & byseven & "#;"
    
          'update EventDate
          db.Execute strSQL, dbFailOnError
    
       End If
    
       'clean up
       rs.Close
       Set rs = Nothing
    
    End Sub
    Closer???

  8. #8
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Is this essentially just a filter? And I can add criteria to it? Could I also modify to use as a 30 day, 90 day, 365 day? Or do a save as? Trying to think how I could use this on my form frmEvent since it is the scheduler form and also has the subform on it that shows a list of the missed transactions! Would I have to a If Statement for every record on my main form to check is it was a daily, weekly, monthly, quarterly or yearly event and then run code?


    Private Sub Form_Current()
    If Me.PeriodTypeID = "d" Then
    byseven
    Else
    If Me.PeriodTypeID = "m" Or "q" Or "yyyy" Or "ww" Then
    Exit Sub
    End If
    End If
    Last edited by burrina; 02-08-2013 at 02:35 PM. Reason: Have to do this?

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    No, not a filter. The query in the code (the strSQL) is an update query. It selects all records to be updated with the date.
    If you want only selected records, you can add criteria. The SQL that uses criteria is commented out. Uncomment the SQL with criteria and comment out the SQL without criteria.

    Could I also modify to use as a 30 day, 90 day, 365 day
    You can change the number of days to add.
    7 is hard coded in the DateAdd() function. You can use "Select Case" to dynamically change the number or days.

    Would I have to a If Statement for every record on my main form to check is it was a daily, weekly, monthly, quarterly or yearly event and then run code?
    Probably... but I would use "Select Case" syntax, not an If() statement.

    Also, the code example was to show how to add 7 days to a date. I'm still not sure of what you are trying to do. Or when you want it to happen. If it is called in a Form_Current event, the code would try to update records in tblmissedtransactions EVERY time the current record changed. You might also have to add arguments. For example

    It would look something like:
    Code:
    Public Sub CalcNewDate(pEventID As Long, pPeriodType As String)
       'Purpose: Find Dates in Increments of 7 Using EventStart Field in tblmissedtransactions.
       'Check if date is in field dteentered and if so, increment 7 days from there.
       'Starting date was EventStart, next date entered is dteentered.
    
    
       Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim strSQL As String
       Dim TheInterval As String
       Dim TimePeriod As Integer
       Dim StartDate As Date
       Dim NewDate As Date
       Set db = CurrentDb()
    
    
       'Get the date
       Set rs = db.OpenRecordset("tblmissedtransactions")
       If rs.BOF And rs.EOF Then
          MsgBox "No records"
       Else
          StartDate = rs!EventStart
          
          Select Case pPeriodType
             Case "d"
                TheInterval = "D"
                TimePeriod = 7
             Case "M"
                TheInterval = "M"
                TimePeriod = 30
             Case "WW"
                TheInterval = "WW"
                TimePeriod = 1
             Case "Q"
                TheInterval = "Q"
                TimePeriod = 1
             Case "YYYY"
                TheInterval = "YYYY"
                TimePeriod = 1
          End Select
    
          'Calc the new date
          NewDate = DateAdd(TheInterval, TimePeriod, StartDate)
    
          'Update EventDate - With criteria
          strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & NewDate & "#"
          strSQL = strSQL & " WHERE tblmissedtransactions.dteentered = " & pEventID & " ;"
    
          'Update EventDate - all records
          '      strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & byseven & "#;"
    
          'update EventDate
          db.Execute strSQL, dbFailOnError
    
       End If
    
       'clean up
       rs.Close
       Set rs = Nothing
    
    End Sub
    You would call this function using

    Call CalcNewDate(EventID, PeriodTypeID)

    PeriodTypeID should be a string = "D, "M", "WW", "Q" or "YYYY"


    Still not really sure what you are trying to do.....

  10. #10
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    If you looked at the 2 pics I posted you will see the results of a list of missed transactions that were not entered. It is a generic list, not taking into account what type of missed transactions it is.Just a list of the dates that it could have been missed on. Since I have Daily, Weekly, Monthly, Quarterly and Yearly types of transactions, I have to trim the list down and match it the transactions it is supposed to be with. For every type of transaction there are also 2 options as well to make it even more confusing. There is the recurring transaction that has no expiration date and then there is the One time transaction that ends when that date comes around. So for simplicity sake i chose the weekly transaction for this scenario. Some weekly transactions are one time and some are recurring. If they are recurring then the PeriodTypeID = 0 if they are a one time trans then the PeriodTypeID = 1 . I also need to check if that one time trans was entered or not and if not and the date is greater than 7 days, just delete it.

    Confusing huh? So now with your code I should be able to see just the weekly transactions in increments of every 7 days? This will help in checking which events need to get entered or not and which dates need to get deleted! Now, viewing the Missed Transactions via my schedule form I will only see matching events for that periodtype, i.e. weekly! If it has been entered or is past the 7 day expiration they get deleted, else they are checked off to be entered as missed events or transactions.

    If you scheduled a weekly check to be written for whatever and the check was not written, it would be a missed transaction correct? So you would need to check how many of these if any were missed and then either dismiss or enter them.

    Thanks for your help, I REALLY appreciate it! Hope I am explaining this well enough. Unsure how to use this code, call it from my form? OnCurrentEvent ? Put it in a module? Can you explain what It is supposed to do ?
    Last edited by burrina; 02-08-2013 at 10:09 PM. Reason: Not on same page with you yet!

  11. #11
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Do you have a copy of my db? Would it help if you do not? Are you willing to help me a bit more? I am unsure of how to call the function since I have multiple criteria?
    If Me.PeriodTypeID = "d" Then
    Call CalcNewDate(EventID, d)
    Else
    Exit Sub End If

    Then proceed on from there? Yes or No? Use a Case Select instead? Or a ElseIF statement?

    Here is what I am trying on the OnCurrentEvent of the subform for missed transactions.

    Private Sub Form_Current() 'Purpose: Call Appropriate Type of Code For Event.
    If Me.PeriodTypeID = "d" Then
    Call CalcNewDate(EventID, "d")
    ElseIf Me.PeriodTypeID = "ww" Then
    Call CalcNewDate(EventID, "ww")
    ElseIf Me.PeriodTypeID = "m" Then
    Call CalcNewDate(EventID, "m")
    ElseIf Me.PeriodTypeID = "q" Then
    Call CalcNewDate(EventID, "q")
    ElseIf Me.PeriodTypeID = "yyyy" Then
    Call CalcNewDate(EventID, "yyyy")
    Else
    Exit Sub
    End If

    End Sub
    Last edited by burrina; 02-08-2013 at 10:47 PM. Reason: New Revised Code

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Do you have a copy of my db?
    No

    Would it help
    Probably


    I am unsure of how to call the function since I have multiple criteria?
    I am unsure how to help you because I don't really understand what you are trying to do.

    In your first post, you asked about incrementing a date field based on a different date field and provided sample code. I answered based on that.
    It is easy to change a date in a field...what I don't understand is what happens after you change the date in the missed transactions table.
    So you change the dates: do you change some of the dates? All of the dates? what is the criteria on what records have the dates changed (if any)?
    What happens to the records in the missed transactions table? Do you then delete the records? Do you review them?

    Obviously you have a complicated dB. You understand the problem, but sometimes (like most of us- I mean me) you have a hard time explaining it.

    Pretend you are teaching someone off the street how to run your database. What are missing transactions? What do you do when there are missing transactions?
    If you think the explanation would be too long for a post, type it in a text file or a Word doc. Ask a question and attach the text/doc file to a post.

  13. #13
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Okay, here goes.You create a record in the table tblEvent via the form frmEvent.This record is a scheduled event, meaning it is to take place sometime in the future.If today is 01/01/2013 and this is a daily scheduled event then the next scheduled transaction or date it would be entered would be on 01/02/2013. There can be 5 different types of events; Daily, Weekly, Monthly, Quarterly, Yearly. For each of these types of events they can be recurring or non-recurring events. Meaning that they have no end date or they are a one time event. Example: You can have a Daily event that is either a continuing event or a one time event. This is a check register db but we are concerned with just the scheduling part of it. I have a module that populates the table tblMissingTransactions with a list of all possible dates that those events could be entered on.From the start date when the event was first entered, i.e. (EventStart, date field in tblEvent) until now. After the table tblMissingTransactions gets populated I then run an append qry to append those records in table tblMissingTransactions into the table tblmissedtransctions.Now I have all of the data I need to begin.I open my form frmEvent and some code runs ; If the next scheduled date is less than today and there is no check number for this record then missev (Is it a missed event?) gets checked as true and also missdte (the missed date) gets updated to today. A qry also runs when the form is opened, qryDELETEAlreadyEnteredTransactions this deletes all records that have been entered already form the table tblmissedtransactions. I also get rid of all non-recurring events that have been entered in tblmissed transactions via some delete queries.An addendum to this is if they have not been entered in 7 days, they get deleted anyway. Sheesh, this is so confusing huh? Now begins the process of filtering the list of missed dates in the tblmissedtransactions so they match the table tblEvent where the scheduling is done. If the event is a Daily event, I really don't have to do anything since tblmissedtransactions shows a list of all possible missed events day by day. If the event or transaction is a weekly transaction then I want to see the list in tblmissedtransactions only show me the list of missed transactions in increments of 7 days.Every 7 days from when it was first entered,i.e. (EventStart). Same thing for Monthly, Quarterly, Yearly. So now when viewing the main form frmEvent you look at the subform frmMissedEventsSub you want to see the matching type of event (PeriodTypeID) and only those missed dates when it was supposed to be entered on.Since the subform is linked by EventID which is the primary key, by default you see the matching type of event, i.e Daily, Weekly, Monthly, Quarterly, Yearly. You want to delete all of the dates in tblmissedtransactions that are not relevant to any type of event. After an event is updated with the data from tblmissedtransactions then you want to delete it from tblmissedtransactions as well.When this record is entered, i.e. updated in tblEvent, it gets a new check number, MyDte (Check Register Date), is marked as not being a missed transaction (missev & missdte) missev is a yes/no field, is it a missed event or not and also missdte is a date field, on what date was it missed? (dteentered) gets a new date (Now) (date when it is entered) and enter (a yes/no field) gets checked as true.It is now entered into the check register. This is my best attempt at walking thru the steps of what happens! Hope I have not left anything out.Oh, yes I did! When the form frmEvent is loaded it calls code from the module to populate the tblMissingTransactions, qry runs to populate tblmissedtransactions so that only the latest data is shown. The old data is cleared out and replaced with new.

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sheesh, this is so confusing huh?
    Very!!


    After an event is updated with the data from tblmissedtransactions then you want to delete it from tblmissedtransactions as well.
    How does this happen??

    For frmEvent, what is the code in "Form_Load" or "Form_Open"?

  15. #15
    qa12dx is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    india
    Posts
    112
    how i do this is i have made a calender table that has all the dates from 1-1-06 (2006 when i made the table) to the year 2049. then i made fields to hold date formated in all possible combinations. like month_number, month_word, year, yyyymmdd, ddd, so on and so forth. i use this table a lot on many of my dbs.

    so if u made this table it is real easy. especially since it is 7 days. pick the date. say 28th aug 2012. so its a tuesday.

    join this calender table to the date field of ur table, and pick all the tuesdays from that date till date.

    the table is in the zip accdb if u want to look
    Attached Files Attached Files

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 01-28-2013, 05:21 PM
  2. Replies: 4
    Last Post: 11-10-2011, 03:16 PM
  3. Replies: 2
    Last Post: 10-08-2011, 06:33 PM
  4. Replies: 2
    Last Post: 04-27-2010, 01:25 PM
  5. Replies: 2
    Last Post: 07-31-2009, 06:56 AM

Tags for this Thread

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