Good Afternoon:
I normally do not use macros, and code everything in VBA. However, I am setting up a scheduled action in Windows and was told that the best thing to do was create a macro for the action. I have a split db, both front- and backends are .accdb. I have a macro called ArchiveData, and in this macro is a RunCode for ExecArchive(). The code in the function is:
Code:
Function ExecArchive()
On Error GoTo Error_Handler
Dim oAccess As Access.Application
Dim sDb, SMacroName As String
Dim bCloseExtDb As Boolean
sDb = "J:\Databases-DO NOT MOVE\XX Tracking System\LarmData\Larm Data.accdb"
SMacroName = "CopyArchiveData"
bCloseExtDb = True
Set oAccess = CreateObject("Access.Application")
oAccess.OpenCurrentDatabase Chr(34) & sDb & Chr(34)
oAccess.DoCmd.RunMacro SMacroName
Error_Handler_Exit:
On Error Resume Next
If bCloseExtDb = True Then oAccess.CloseCurrentDatabase
Set oAccess = Nothing
Exit Function
Error_Handler:
MsgBox "The Following error has occured." & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: ExecExternalMacro" & vbCrLf & _
"Error Description: " & Err.Description, _
vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function
This code is meant to run a macro (CopyArchiveData) in the backend. Not sure if this is relevant but this CopyArchiveData calls a RunDataMacro in the source table to copy records to another table. If has a ForEachRecord from the source and a CreateRecord to the archive table.
The backend is not open when I run it and have double checked the file path and name. I must be missing something here. I am thoroughly and utterly confused with this macro to call a function to call a macro structure. I would appreciate any assistance that might be offered.