Just Curious (1 Viewer)

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
I was wondering.... If I wanted certain forms or reports to print out at a certain time each day without any user interaction where would I go to do that? Would it be in vb code, in the actual form or report, or somewhere else?
 

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
Thank you. I believe I found what you are referring to....

Code:
Option Compare Database
Option Explicit

'module to auto-generate PM's into table
'is run by the timer on the switchboard form
'note this means that the first computer to
'run the switchboard after midnight will auto-generate.
'last date PM's were generated
Private DateChecked As Date
Public Sub PMGenerate()
    If DateChecked = 0 Then
        'set DateChecked to last day a PM was generated
        
        Dim qdLastDate As DAO.QueryDef
        Dim rsLastDate As DAO.Recordset
        
        Set qdLastDate = CurrentDb.QueryDefs("PM Last Generate Date")
        Set rsLastDate = qdLastDate.OpenRecordset
        
        If rsLastDate.EOF Then 'the very unlikely event that the PM history table is empty
            DateChecked = Date - 1 'assume yesterday print date, forces generation on next check
        Else 'set date checked...
            DateChecked = rsLastDate.Fields("LastDate")
        End If
            
    ElseIf Date > DateChecked Then
        'a new day that hasn't seen PM's generated- so generate them
        
        Dim strQuery As String
        
        'decide which version to use
        If DatePart("w", Date) = 1 Or DatePart("w", Date) = 7 Then
            strQuery = "PM Print List Append Weekends"
        Else
            strQuery = "PM Print List Append"
        End If
        
        DoCmd.SetWarnings False
        DoCmd.OpenQuery strQuery, acViewNormal, acEdit
        DoCmd.SetWarnings True
        
        DateChecked = Date
        
    End If
    
    
End Sub
 

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
One question I do have though...

Code:
'decide which version to use
        If DatePart("w", Date) = 1 Or DatePart("w", Date) = 7 Then
            strQuery = "PM Print List Append Weekends"
        Else
            strQuery = "PM Print List Append"
        End If

I believe... if I am reading this right... that the 7 here annotates every seven days. Does that look right?
 

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
so what you are saying is that
Code:
'decide which version to use
        If DatePart("w", Date) = 1 Or DatePart("w", Date) = 7 Then
            strQuery = "PM Print List Append Weekends"
        Else
            strQuery = "PM Print List Append"
        End If

the "1" in this code annotates Sunday since that is the default first day of the week?
 

plog

Banishment Pending
Local time
Today, 06:54
Joined
May 11, 2011
Messages
11,613
Yes, that designates Sunday.
 

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
ok... so if I change that "1" to a "7" then the PM's will generate on a Saturday when the db is opened initially instead of the sunday they are currently generating on... thank for all the help!!!
 

plog

Banishment Pending
Local time
Today, 06:54
Joined
May 11, 2011
Messages
11,613
The code section you posted doesn't control when the query runs, it controls what query runs. Also, if you will notice, Saturday is already being lumped together with Sunday.


I don't know what your endgame is, but this seems seperate from your initial question. If you want to something to execute a specific date/time of the week I advise you use the windows task scheduler I referenced in my first post.
 

Prayder

Registered User.
Local time
Today, 06:54
Joined
Mar 20, 2013
Messages
303
I apologize for being confusing. Right now on Sunday night/Monday morning at 12:01 AM we have scheduled PM's that print off when the database is opened and I am trying to change that to print off on Sunday morning/Saturday night at 12:01 AM
 

Users who are viewing this thread

Top Bottom