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"
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"