Macro/Form Open Action (1 Viewer)

evictme

Registered User.
Local time
Today, 17:22
Joined
May 18, 2011
Messages
168
Hello All,

I have a question in regards to a macro that runs a form open command:

The macro opens a form that executes a host of commands on open. I want to add an IF statement to the Macro but im not sure if it should be in the Macro or the Form Open Actions

I would like for the Macro/Form to check if the Macro has run within the past 10-20 minutes and if so the macro does nothing.

Is there a way to incorporate that into the macro or is there some language I can add to the form_open action that will check this?

Any help would be greatly appreciated!

Thanks,

- E

The Form VBA:
"Private Sub Form_Open(Cancel As Integer)
Dim FileName As String

On Error GoTo Err_Form_Open

If DCount("[Client ID]", "qry - Clients Current") > 0 Then
FileName = "Clients " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "qry - Clients Current", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
If DCount("[Client ID]", "qry - Tasks Purge") > 0 Then
FileName = "Tasks " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "qry - Tasks Purge", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
If DCount("[EE ID]", "qry - Employees Current") > 0 Then
FileName = "Employees " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "qry - Employees Current", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
If DCount("[EE ID]", "qry - WebUsers Current") > 0 Then
FileName = "WebUsers " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "qry - WebUsers Current", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
If DCount("[Client ID]", "qry - Budgets") > 0 Then
FileName = "Budgets " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "qry - Budgets", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
Call GenerateSiteGroupJobTitles
If DCount("[SiteGroupID]", "temp - SiteGroup") > 0 Then
FileName = "SiteGroups " & Format(Now, "yyyy-mm-dd hh-nn") & ".csv"
DoCmd.TransferText acExportDelim, , "temp - SiteGroup", Me.Import & "Temp\" & FileName, True
Call moveCurrent(FileName, Me.Import & "Temp\", Me.Import)
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry - Clients Archive"
DoCmd.OpenQuery "qry - Employees Archive"
DoCmd.OpenQuery "qry - Budgets Archive"
DoCmd.SetWarnings True
DoCmd.Close acForm, "Export - All Files"

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub"
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:22
Joined
Aug 30, 2003
Messages
36,125
Well, if you want to check the last time it was opened, you'll need to save that. Options include a public variable, a single-record table, and perhaps a TempVar (which I haven't used). I'd use the first or second. Then you can use the DateDiff() function to check that time against Now(). If it's greater than 10 minutes, open the form and update the value, if not don't open the form and perhaps give the user a message box.
 

Users who are viewing this thread

Top Bottom