How to SaveAs the CurrentDb to a different filename?

  • Thread starter Thread starter EagleOne
  • Start date Start date
E

EagleOne

2003

What (series of) commands in VBA will save my current database as a different filename?

MY attempts included (to no avail):

Dim TempFile As Object
Set TempFile = CurrentDb
TempFile.SaveAs CurrentProject.Path & "\" & MyNewFileName

I am probable making this more difficult than needs be but I cannot find the combination.

Thanks EagleOne
 
2003

What (series of) commands in VBA will save my current database as a
different filename?

MY attempts included (to no avail):

Dim TempFile As Object
Set TempFile = CurrentDb
TempFile.SaveAs CurrentProject.Path & "\" & MyNewFileName

I am probable making this more difficult than needs be but I cannot
find the combination.

Thanks EagleOne

Forgetting for a moment that it is not a good idea to copy a file while it
is open...you would use the FileCopy() function.

An MDB is not a "document" and has no Save As.
 
2003

What (series of) commands in VBA will save my current database as a
different filename?

MY attempts included (to no avail):

Dim TempFile As Object
Set TempFile = CurrentDb
TempFile.SaveAs CurrentProject.Path & "\" & MyNewFileName

I am probable making this more difficult than needs be but I cannot
find the combination.

Thanks EagleOne

Forgetting for a moment that it is not a good idea to copy a file while it
is open...you would use the FileCopy() function.

An MDB is not a "document" and has no Save As.
 
That is why I can not find the combination!

That said, I tried:

Dim OldFile As String, NewFile As String
OldFile = CurrentProject.Path & "\" & CurrentProject.Name
NewFile = CurrentProject.Path & "\CECAR - JAMAA " & Replace(Date, "/", "-") & " " & Time() & ".mdb"
CurrentDb.Close
FileCopy(OldFile, NewFile)

The FileCopy as above does not work - asks for an = sign
Also, FileCopy OldFile, NewFile it also does not work

TIA EagleOne

What is the syntax for FileCopy in Access?
 
That is why I can not find the combination!

That said, I tried:

Dim OldFile As String, NewFile As String
OldFile = CurrentProject.Path & "\" & CurrentProject.Name
NewFile = CurrentProject.Path & "\CECAR - JAMAA " & Replace(Date, "/", "-") & " " & Time() & ".mdb"
CurrentDb.Close
FileCopy(OldFile, NewFile)

The FileCopy as above does not work - asks for an = sign
Also, FileCopy OldFile, NewFile it also does not work

TIA EagleOne

What is the syntax for FileCopy in Access?

Get rid of the parenthesis.

The following works for me. It fails with the parenthesis.

FileCopy "c:\CurrentFolder\MyDb.mdb", "c:\NewFolder\MyDb.mdb"
 
(e-mail address removed) wrote in
What (series of) commands in VBA will save my current database as
a different filename?

MY attempts included (to no avail):

Dim TempFile As Object
Set TempFile = CurrentDb
TempFile.SaveAs CurrentProject.Path & "\" & MyNewFileName

I am probable making this more difficult than needs be but I
cannot find the combination.

I can't believe no one has suggested Lyle's SaveAsText trick:

Application.SaveAsText 6, vbNullString, [name of backup copy]
 
Excellent idea!

David W. Fenton said:
(e-mail address removed) wrote in
What (series of) commands in VBA will save my current database as
a different filename?

MY attempts included (to no avail):

Dim TempFile As Object
Set TempFile = CurrentDb
TempFile.SaveAs CurrentProject.Path & "\" & MyNewFileName

I am probable making this more difficult than needs be but I
cannot find the combination.

I can't believe no one has suggested Lyle's SaveAsText trick:

Application.SaveAsText 6, vbNullString, [name of backup copy]
 
(...)
I can't believe no one has suggested Lyle's SaveAsText trick:

Application.SaveAsText 6, vbNullString, [name of backup copy]

Good idea. But this trick (SaveAsText 6) copies tables only. To copy whole
open database, You may write something like this (although copying open
files is not recommended):

Public Declare Function CopyFileA Lib "kernel32" _
(ByVal FileName As String, ByVal NewFileName As String, _
ByVal FailIfExists As Long) As Long

CopyFileA CurrentDb.Name,"D:\BackupCopy.mdb",0


K.P.
 
Thanks for your knowledge & time.

Krzysztof Pozorek said:
(...)
I can't believe no one has suggested Lyle's SaveAsText trick:

Application.SaveAsText 6, vbNullString, [name of backup copy]

Good idea. But this trick (SaveAsText 6) copies tables only. To copy whole
open database, You may write something like this (although copying open
files is not recommended):

Public Declare Function CopyFileA Lib "kernel32" _
(ByVal FileName As String, ByVal NewFileName As String, _
ByVal FailIfExists As Long) As Long

CopyFileA CurrentDb.Name,"D:\BackupCopy.mdb",0


K.P.
 
(...)
I can't believe no one has suggested Lyle's SaveAsText trick:

Application.SaveAsText 6, vbNullString, [name of backup copy]

Good idea. But this trick (SaveAsText 6) copies tables only. To
copy whole open database,

Why would you ever need to copy your front end? Of course, I assume
you have a split database, which is the only way any Access app
should be deployed.
You may write something like this (although copying open
files is not recommended):

Public Declare Function CopyFileA Lib "kernel32" _
(ByVal FileName As String, ByVal NewFileName As String, _
ByVal FailIfExists As Long) As Long

CopyFileA CurrentDb.Name,"D:\BackupCopy.mdb",0

This will not produce a good copy in all circumstances, since the
file is open.
 
Back
Top