Open a new database from inside access

Valentine

Member
Local time
Yesterday, 23:54
Joined
Oct 1, 2021
Messages
261
Hello everyone I am brand new to this forum and have a question that has plagued me for a few days now.

I created a cmd button to do backup and i want to open one of the copied database front ends to unlink the tables but can't seem to figure out how to open the specific new database.
 
dim accessapp as object
set accessapp = createobject("access.application")
accessapp.opencurrentdatabase "path to file"

this has the benefit of not opening the other file from 'within' the same instance of access where the code is running, which will generally complicate things for you, depending on what you want to do with the other file
 
Last edited:
Hi. Welcome to AWF!

One simple approach to open a file is by using the FollowHyperlink method. Do you know the full filepath of the file you want to open?
 
I am trying to perform a complete backup with 1 button push on our operational FE. I have the button creating a copy and putting it into our backup folder i want the button to also open that specific FE non visible and unlink all the tables so finish the backup process per our procedures.
 
I am trying to perform a complete backup with 1 button push on our operational FE. I have the button creating a copy and putting it into our backup folder i want the button to also open that specific FE non visible and unlink all the tables so finish the backup process per our procedures.
Hmm, interesting. I can't imagine why you would need to back up the FE. You should always keep a "master copy" of the FE in a safe place, and use it to refresh all other copies of the users' FEs. Instead, what you would typically need to backup is the BE or the data.

Here's one approach I use to backup the BE. Why are you backing up the FEs? Just curious...

 
Currently we are linked to Sharepoint so all of our backend is online so if i just copy the FE and unlink the tables it creates its own standalone backup for our information.
 
Currently we are linked to Sharepoint so all of our backend is online so if i just copy the FE and unlink the tables it creates its own standalone backup for our information.
Hi. Thanks for the clarification. As I was saying though, your current backup process keeps making a backup of the FE objects, which shouldn't have changed in between backups. Maybe it's just the convenience aspect that's why you're doing it this way, but I would probably recommend just exporting the linked tables into Excel files (or event Access tables into an empty database file) to backup the data only. This way, you won't need to waste any space storing the FE objects (forms/reports/etc.) and also don't have to figure out how to unlink the tables in the backup file. I am not saying it's not possible, I am just offering a potentially (in my perspective) simpler approach for creating a local backup copy of your data.
 
The sharepoint part of this is run by a different section and we would just like to have our own backup incase things hit the fan.
 
The sharepoint part of this is run by a different section and we would just like to have our own backup incase things hit the fan.
Hi. Like I said, if you are just concerned about the data, you should be able to export them out of the front end into either Excel or Text (CSV) or another Access file. That would be easier to code than the approach you're trying now (although your approach is not impossible).
 
So i brought up that we should be doing it your way but was told that since the way that was first asked is an actual viable solution they would rather we go the harder route.......
 
So i brought up that we should be doing it your way but was told that since the way that was first asked is an actual viable solution they would rather we go the harder route.......
LOL. I guess you're stuck with it. :)

I'll have to run some tests to see how we can make that happen. I'll let you know what I find.
 
Currently we are linked to Sharepoint so all of our backend is online so if i just copy the FE and unlink the tables it creates its own standalone backup for our information.
Hi. I haven't started with my experiments yet, but I'd like to clarify the above statement. Typically, you would use code to automate manual tasks. So, to make sure I completely understand what you're trying to do, could you please explain to us the manual steps you would use to create a backup copy of your company's data from SharePoint?

I imagine you might say something like this:
  1. Right-click on the FE and select Copy
  2. Navigate to the Backup folder, right-click and select Paste
  3. Open the newly copied FE
  4. and then what?...
I am trying to see what is the step to make the online data become local data. Thanks!
 
Hi. I haven't started with my experiments yet, but I'd like to clarify the above statement. Typically, you would use code to automate manual tasks. So, to make sure I completely understand what you're trying to do, could you please explain to us the manual steps you would use to create a backup copy of your company's data from SharePoint?

I imagine you might say something like this:
  1. Right-click on the FE and select Copy
  2. Navigate to the Backup folder, right-click and select Paste
  3. Open the newly copied FE
  4. and then what?...
I am trying to see what is the step to make the online data become local data. Thanks!
your steps are accurate, then i would go to each table and right click and select "convert to local" we have roughly 20 - 30 tables that i have to make local for the backup to be finished. 1 or 2 of them roughly take like 5 min each but majority are almost instantaneous. After the tables are local just exit the database and go home for the weekend.
 
Welcome aboard:)

You would define a db object and assign it to the database you want to open rather than Currentdb Once you have that db object, you can manipulate tabledef objects.

However, why are you doing this? Typically when you want to replace the FE with an updated one, you take YOUR development copy which should be linked to a test BE and relink it to the production BE before moving it to the master folder on the server. You should be using either a batch file or a special database to distribute the updated FE to each user as he opens the app. I cannot envision a scenario where you would want to reach out and update some user's copy of the FE this way.

If you tell us more about what you are trying to accomplish, we can offer advice.
so in doing this would this pick up the most recent copy of the DB or just a new DB? I am trying to make the button copy the FE and then open that specific copy to make the tables local.
 
your steps are accurate, then i would go to each table and right click and select "convert to local" we have roughly 20 - 30 tables that i have to make local for the backup to be finished. 1 or 2 of them roughly take like 5 min each but majority are almost instantaneous. After the tables are local just exit the database and go home for the weekend.
Okay, thanks for the clarification. Considering the ultimate goal is to have an exact duplicate of the FE with local copies of the linked SharePoint tables, there are several ways to go about getting it done. The way you want to do it, in my humble opinion, is the "most expensive" approach, because you will continually recreate existing (no changes) objects, which I would consider not necessary and could be deferred later when you actually have to use the backup copy of your database.

Still, to get the same result, you can also use other approaches where you only perform the table conversion process and still end up with a full backup copy of the database with all the objects and local tables together. These approaches are "less expensive" than the first approach, but I won't consider them optimal. However, as you said, the marching orders from the higher ups is not to use the optimal approach, but just to get it done.

So, in the spirit of just automating what you already started with, I came up with the following:
Code:
Public Function SP2Local(strDB As String) As Boolean
'thedbguy@gmail.com
'10/27/2021
'converts SharePoint linked tables to local tables
'pass the complete filepath and filename of the backup db to this function
'for example: SP2Local "C:\BackupFolder\BackupFilename.accdb"

Dim app As Object
Dim db As DAO.Database
Dim tdf As DAO.TableDef

'open external db
Set app = CreateObject("Access.Application")
Set db = app.DBEngine.OpenDatabase(strDB)

'convert linked tables
For Each tdf In db.TableDefs
    With tdf
        If InStr(.Connect, "ACEWSS") > 0 Then
            app.DoCmd.SelectObject acTable, .Name, True
            app.DoCmd.RunCommand acCmdConvertLinkedTableToLocal
        End If
    End With
Next

MsgBox "All done!", vbInformation, "Info"

'cleanup
db.Close
Set db = Nothing
Set app = Nothing

End Function
Hope that helps...
 
Last edited:
sorry about that internet in the army sucks. What i was trying to say is that doesn't that code require me to have copied the front end before because you are bringing it in as a variable from outside. I am trying to copy and then open that copy in the same button click code.
 
sorry about that internet in the army sucks. What i was trying to say is that doesn't that code require me to have copied the front end before because you are bringing it in as a variable from outside. I am trying to copy and then open that copy in the same button click code.
Yes, that's what you said earlier you were trying to do. So, here's what I am saying you could have in your code.

(pseudocode vba)
1. click_event starts
2. vba code to copy the FE file (I thought you already have this part - I mean, in your original post and in the title of your thread, I got the impression you managed to make a copy of the FE but just need to figure out how to open it to convert the linked tables into local tables)
3. call the function I gave you at this point, passing the filepath for the file you just created above
(that's it)

Do you need help with any of those steps?
 
yeah after i typed that i realized i could just pull in the name of the DB that i created as the strDB in your code. I am awaiting permission to test on an actual linked table to see if what i put in will work.
 

Users who are viewing this thread

Back
Top Bottom