How to SaveAs the CurrentDb to a different filename?

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
 
R

Rick Brandt

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.
 
R

Rick Brandt

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.
 
E

EagleOne

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?
 
F

fredg

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"
 
D

David W. Fenton

(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]
 
E

EagleOne

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]
 
K

Krzysztof Pozorek [MVP]

(...)
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.
 
E

EagleOne

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.
 
D

David W. Fenton

(...)
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.
 

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