Quote:
Originally Posted by gjgriffith
So, to make this work, you need to create a new instance of Access and open the database in the new instance and then call the RunCommand to toggle online/offline...and of course, the database cannot be opened in any other instance of Access when you do that.
|
I realize I am a little late to the party and hopefully some of the party-goers are still awake...
When I attempted to do this procedure some curious things happened. I am using Access 2010 and SP 2007.
Here is my code:
Code:
Option Compare Database
Option Explicit
Dim appAccess As Access.Application
Sub ToggleSharePoint()
On Error GoTo err_handler
Dim strDB As String
Const strConPath = "C:\Test_DB\"
strDB = strConPath & "myDB.accdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strDB
Access.RunCommand (Access.AcCommand.acCmdToggleOffline)
MsgBox "Done"
exit_handler:
Exit Sub
err_handler:
MsgBox Err.Number & " - " & Err.Description
Resume exit_handler
End Sub
I am able to run this sub from the immediate window and it works flawlessly. I can run Access.RunCommand (Access.AcCommand.acCmdToggleOffline) from the IW as well and get the same results.
However, when I attempt to do this from a Form's Command Button, I get the same error as the OP, which was addressed already.
I changed to procedure from and Sub to a Function and tried to run it at startup as part of the AutoExec Macro...and that is when the funky stuff started...
My application started opening multiple times in an infinite loop - about 100 instances until I was able to stop it. What is more, not once did I get my MsgBox "Done" to assure me the code had worked...AND...no errors were thrown.
I am at a loss on
1. Why the code isn't working
2. How to toggle SP on and off with VBA
I purchased the A2010 Programmer's Reference and read and re-read chapter 19 and could not find any help there.
Is what I am trying to do just not possible?