Message Box behaving weirdly

stephen81

Registered User.
Local time
Today, 13:21
Joined
Nov 27, 2002
Messages
198
I'm using ghudson's backupandzipit function with a few alterations which is working fine. I get a backup file called filename.mdb-Backup_yy_mm_dd which is what I want but the message boxes return mypath\filename.mdb for sBackupPath and -Backup_yy_mm_dd for sBackupFile whereas I want mypath\ for sBackupPath and filename.mdb-Backup_yy_mm_dd for sBackupFile.



PHP:
Public Function Backup()

'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!

'Thanks to Ricky Hicks for the .CopyFile code

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")
strFile = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=False, _
                DialogTitle:="Save backup as...", _
                Flags:=ahtOFN_HIDEREADONLY)


sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
sSourceFile = Dir(CurrentDb.Name)
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") & ".mdb"


Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing

MsgBox sBackupPath
MsgBox sBackupFile


End Function


Can anyone see what I'm doing wrong?
 
what does strFile return?

stephen81 said:
I'm using ghudson's backupandzipit function with a few alterations which is working fine. I get a backup file called filename.mdb-Backup_yy_mm_dd which is what I want but the message boxes return mypath\filename.mdb for sBackupPath and -Backup_yy_mm_dd for sBackupFile whereas I want mypath\ for sBackupPath and filename.mdb-Backup_yy_mm_dd for sBackupFile.



PHP:
Public Function Backup()

'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!

'Thanks to Ricky Hicks for the .CopyFile code

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")
strFile = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=False, _
                DialogTitle:="Save backup as...", _
                Flags:=ahtOFN_HIDEREADONLY)


sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
sSourceFile = Dir(CurrentDb.Name)
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") & ".mdb"


Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing

MsgBox sBackupPath
MsgBox sBackupFile


End Function


Can anyone see what I'm doing wrong?
 
It returns exactly the same as sBackupPath
i.e. mypath\filename.mdb
 
...confused...

when I tried a basic version of your code, it returned correct sBackupPath & sBackupFile...

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
'strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")
strFile = YOURFILENAME

sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
sSourceFile = Dir(CurrentDb.Name)
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") & ".mdb"


'Set fso = New FileSystemObject
'fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
'Set fso = Nothing

MsgBox sBackupPath
MsgBox sBackupFile

...try this basic code & enter the actual full file path in YOURFILENAME....

stephen81 said:
It returns exactly the same as sBackupPath
i.e. mypath\filename.mdb
 
It still returns path\filename.mdb for sBackupPath and -Backup_yy_mm_dd for sBackupFile. I'm going home soon so I'll try again tomorrow and see if my computer has decided to start behaving again. I'll let you know.

Thanks

Stephen
 
It's definitely still doing the same thing. My code now reads

Code:
Public Function Backup()

Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")

strFile = "S:\mypath\test.mdb"

sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
sSourceFile = Dir(CurrentDb.Name)
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") 

MsgBox strFile
MsgBox sBackupPath
MsgBox sBackupFile


Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing


MsgBox sBackupPath
MsgBox sBackupFile

End Function
 
Good morning,

I think I've figured it....
If strFile dosn't exist, sBackupPath = strFile

Check to see the correct file path is being entered....try simplifiying the code & forget about the copying for now....

stephen81 said:
It's definitely still doing the same thing. My code now reads

Code:
Public Function Backup()

Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")

strFile = "S:\mypath\test.mdb"

sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
sSourceFile = Dir(CurrentDb.Name)
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") 

MsgBox strFile
MsgBox sBackupPath
MsgBox sBackupFile


Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing


MsgBox sBackupPath
MsgBox sBackupFile

End Function
 
I suggest that you use message boxes to display the value of your strings
so that you can monitor what is being used when the code is running.
See where I placed the msgbox commands below...
Code:
Public Function Backup()

'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!

'Thanks to Ricky Hicks for the .CopyFile code

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String


Dim strFilter As String
Dim strFile As String
strFilter = ahtAddFilterItem(strFilter, "Microsoft Access (*.mdb)", "*.mdb")
strFile = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=False, _
                DialogTitle:="Save backup as...", _
                Flags:=ahtOFN_HIDEREADONLY)


sSourcePath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
msgbox "sSourcePath = " & sSourcePath
sSourceFile = Dir(CurrentDb.Name)
msgbox " sSourceFile = " & sSourceFile
sBackupPath = Left(strFile, Len(strFile) - Len(Dir(strFile)))
msgbox "sBackupPath = " & sBackupPath
sBackupFile = Dir(strFile) & "-Backup" & "_" & Format(Date, "yy_mm_dd") & ".mdb"
msgbox "sBackupFile + " & sBackupFile


Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
msgbox "fso.CopyFile = " & sSourcePath & sSourceFile, sBackupPath & sBackupFile
Set fso = Nothing

MsgBox sBackupPath
MsgBox sBackupFile


End Function
HTH
 

Users who are viewing this thread

Back
Top Bottom