utilize getopenfilename dialog

G

Gntlhnds

I am trying to incorporate some code to compact/backup my backend, but since
my backend resides on a server and the front end is on my local machine, it
doesn't work. What I would like to do is utilize the GetOpenFileName dialog
to browse to the backend. Here's the code that I have now:

Function DoBackup()
On Error GoTo Err_DoBackup


Dim strBackupFile As String
Dim strCurrentFile As String
Dim strDateStamp As String
Dim strCurrentLockFile As String



strCurrentFile = Application.CurrentProject.Path & "\Tables.mdb"
DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")
strBackupFile = Application.CurrentProject.Path & "\Backup\" &
strDateStamp & ".mdb"
strCurrentLockFile = Application.CurrentProject.Path & "\Tables.ldb"

If Len(Dir(strCurrentLockFile)) > 0 Then
MsgBox "Cannot backup the database: it's in use", , "Backup "
Else
If Len(Dir(strBackupFile)) > 0 Then
Kill strBackupFile
End If
Application.CompactRepair strCurrentFile, strBackupFile
Kill strCurrentFile ' or better to rename it
Application.CompactRepair strBackupFile, strCurrentFile
DoCmd.Beep
MsgBox "Database backup successful...", , "Backup Confirmation"

End If
' Copy the database
DoCmd.Hourglass False

Exit_DoBackup:
Exit Function


Err_DoBackup:
MsgBox Str(Err)
MsgBox Error$
Resume Exit_DoBackup

End Function

This code works great if the FE and BE are in the same folder. Since I
don't know the path to the backend for my users, I prefer to use the
GetOpenFileName dialog to browse to it and also to specify the name and
location of the backup file (preferably with a default name filled in for
them to change if they like). Thanks for your help.
 
G

Gntlhnds

I have both of those codes, but I don't know how to incorporate it into my
existing code below. Right now, as a work around, I keep the front end in
the same folder as the back end, and just copy a shortcut to my desktop. I
have a slow network, though, and this is proving cumbersome. Plus, I'd still
like to specify where to save the backup copy to. I have the API code to
open the dialog box, but I'm at a lost at trying to write into the code for
doing the backup.
 
G

Gntlhnds

Thank you for your help. That worked great. What I would like to do,
though, is something like you mentioned in your first reply. I would like to
get the path from the linked table property, but I can't connect to the link
you gave and I haven't figured out how to incorporate the one from the
mvps.org website (http://www.mvps.org/access/tables/tbl0007.htm) into my
code. What I have now works, but I don't have any code for handling the
"cancel" button (I don't know what or where to put it). Here is what I have
now:

Dim strBackupFile As String
Dim strCurrentFile As String
Dim strDateStamp As String
Dim strCurrentLockFile As String

strCurrentFile = ahtCommonFileOpenSave(DialogTitle:="Please Select the
File with Your Tables")

DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")

strBackupFile = ahtCommonFileOpenSave(FileName:=strDateStamp,
DefaultExt:="mdb", DialogTitle:="Save Backup...", OpenFile:=False)

strCurrentLockFile = strCurrentFile & ".ldb"
 
A

Alex Dybenko

Hi,
to handle cancel button - you just need to check length of the string after
this line:
strCurrentFile = ahtCommonFileOpenSave(DialogTitle:="Please Select the
File with Your Tables")

if len(strCurrentFile)=0 then
'cancel pressed
else
'something was selected
end if

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
G

Gntlhnds

Thanks for your help. By browsing through all the code written in these
newsgroups I should have been able to figure that out, but since I'm
obviously new at writing code I couldn't quite figure out how to put that
code in mine, but I got it to work. I still like the idea of being able to
use the linked table property to get the paths automatically, and I've been
playing with the code to try and get it to work, but I haven't had any luck.
I've copied the code from the mvps.org website into a new module, but I
haven't the faintest clue as to how to incorporate it into my current code.
What do I set strCurrentFile, strBackupFile, and strCurrentLockFile to?
 
G

Gntlhnds

Thanks for that. It's a good thing I checked this at home. For some reason
the firewall at work was preventing me from being able to view your site.
I'll try this at work and see what I can come up with. I don't have Access
at home so I'm going to have to wait until I get to work. I appreciate your
patience.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top