Code to Work Offline

crann

Registered User.
Local time
Today, 19:05
Joined
Nov 23, 2002
Messages
160
Hi

Really struggling with this one.

I have a database that is linked to share point however if I have no Internet access I am unable to open database unless I put it into work offline mode.

Is there anyway I can use a piece of code to create a button that will simply put the database into offline or online mode without having to keep going to the external data tab.

I have tried looking through Web but can't seem to find what I am looking for.

Grateful for any help
Thanks
Crann
 
I think it's this command:
Code:
DoCmd.RunCommand acCmdToggleOffline
 
Hello thanks for reading.

I'm only a beginner so I've assumed I could paste that could into the on click event of a new cmd button.

When I run it comes up with a run time error and highlights the code yellow

Not sure what that means tbh

Thanks

Crann
 
Hi

When I click the button I get this:

Run-time error '2501'

The RunCommand action was canceled

Thanks
Jon
 
Are all the tables and queries closed before running the command? And also ensure that the form is unbound and no report/form is opened.
 
Hi

I have created the cmd button on my navigation form.

Nothing other than the Nav form is open. I have reloaded the database to make sure.

Thanks

Jon
 
Ok, you've done all that but have you re-tested it? And if you have what was the exact outcome?

Are you sure that Nav form doesn't have forms that are bound to a table/query?
 
Hello

OK so this nav for does contain several Command buttons to launch other forms which will be bound to tables.

Some other information:
The database does have a user login system before launching that nav firm and I have a couple of pop up reminders that check insurance renewal dates from a table and also a task reminder.
Would any of these be an issue.

Thanks

Jon
 
Allow me to re-iterate.
Ok, you've done all that but have you re-tested it? And if you have, what was the exact outcome?

Some other information:
The database does have a user login system before launching that nav firm and I have a couple of pop up reminders that check insurance renewal dates from a table and also a task reminder.
Would any of these be an issue.
I don't know. You will have to test it.
 
Yes retested and the same error message

Thanks again
 
Do you know how to open another database using code? Look into that and I'll tell you what next to add.
 
Hi

I am able to open another one of my db's from a command button on this Navigation form using this code:

Private Sub Command126_Click()
Dim accapp As Access.Application

Set accapp = New Access.Application

accapp.OpenCurrentDatabase ("C:\Users\Jonathan\Desktop\tester.accdb")
accapp.Visible = True
End Sub

Is that what you meant by opening another db by code?

Very grateful for your help

Jon
 
Very good! Nice to see when someone takes the initiative ;)

Create a new db with just one form and one button, and run this code in the button:
Code:
Private Sub Command126_Click()
    Dim accapp As Access.Application
    
    Set accapp = New Access.Application
    
    With accapp
        .OpenCurrentDatabase ("[COLOR="Blue"]C:\Users\Jonathan\Desktop\tester.accdb[/COLOR]")
        .Visible = True
        .RunCommand acCmdToggleOffline
        .CloseCurrentDatabase
    End With
    
    Set accapp = Nothing
End Sub
Change the database path to the one you're trying to make offline. Make sure that the database isn't open before you run the code.
 
Ok some action :)

So now I have a new db with one command button that when I run it takes my required main db offline

Thanks

Jon
 
My natural two next questions

1. how do I change the code to put it back online (can i just change toggleoffline to toggleonline)???

2. Can we now get that command button into the main database so I can toggle on and offline from my main Nav form?

thanks

Jon
 
1. It's the same code. It changes it from Online to Offline and Offline to Online.
2. In the new db, add code that will close your main db, open it, toggle it, then make it visible. And after doing this, close the new db.
 
Ok didn't realise code was working both ways.

Currently I have no idea how to construct that series of code as still learning but I assume what I am really doing is always opening the new db and launching the main db immediately on its startup then toggling its online/offline status then closing the new database so it appears i've always launched the main db?
:banghead:

Thanks for all your help

Jon
 
Ok, let's run some tests.

1. In your main db, create a blank form and in the load event just put the one line of code that toggles the online status. Set this form as the Startup Form. Now close and open your db and tell me if it changes the online status. Do it a few times and tell me the result.
2. Another test, add the following code to a module and run it. Look in the Immediate Window and tell me what values you see:
Code:
Public Sub GetOfflineProp()
    Dim prop As Variant
    Dim db   As DAO.Database
    
    Set db = CurrentDb
    
    For Each prop In db.Properties
        With prop
            If .Name Like "*offline*" Or .Name Like "*toggle*" Then
                Debug.Print .Name
            End If
        End With
    Next
End Sub
 
Ok
I am trying to keep up here.

When I run the onload event i get the same runtime 2501 message on startup.

I created that module and in the immediate window its says: HasOfflineLists

jon
 

Users who are viewing this thread

Back
Top Bottom