Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename current database 2

Status
Not open for further replies.

ameedoo3000

IS-IT--Management
Sep 20, 2016
233
EG
hi every body
how can i rename my current database after close it automaticly with vba code
 
This is a bit unusual. I can't imagine this is possible without opening your database with another program or script that pauses when your database is open and then renames after it is closed.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
I would try open the Access file with a simple batch file and then renames the Access file after it closes. Have you tried this?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
I would like to know - WHY do you want to do it [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I already did this through another Access file and the name was not changed. I did it again using bat file and the name was not changed either.
The file whose name is to be changed must be closed first, then another file can be opened through which the name can be changed.... Is there no other way?
 
The purpose of changing the file name and extension after completing work on it is to hide it and not steal it
 
What is the code when closing an access file (renaming it) using the Start /wait statement?
 
ameedoo3000 said:
I already did this [rename the file?] through another Access file and the name was not changed
How did you do it? What did you try? Code sample would be nice to see.
Was the file 'not in use' any more? Not used by any other process?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Name_1_qvrcdv.png


Code:
Private Sub RenameFile()
Dim strPath As String
Dim strOrgFile As String
Dim strNewFile As String

strPath = "C:\SomeFolder\"
strOrgFile = "MyFile.txt"
strNewFile = "NewFileName.xyz"
[blue]
Name [/blue]strPath & strOrgFile [blue]As[/blue] strPath & strNewFile

End Sub

Name_2_zognlw.png


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andy,
I believe the OP wants to rename the current Access file which can't be done while the file is open.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
The Access file that I want to keep, I save it on the hard disk without an extension, so as not to steal it on it, and when I want to use it, it is through another Access file, which changes the name and extension, and then runs it... as shown vba code
1- Name "File path and name without extension" As "File path and name with extension "
2- Call OpenAccessDatabase("File path and name with extension ")
All I want is when I close this file, its name, location, and extension are changed so as not to steal it
I tried this code in the file closing event and the requested change did not occur
1- Docmd.quit
2- Name "File path and name with extension" As "File path and name without extension "
I tried to open the bat file after closing the access file, and it contains instructions to change the name and extension of the access file, but nothing was changed either... as shown.
1- Docmd.quit
2- Dim myPath As String
3- myPath = "file path\filename.bat"
4- Call Shell(myPath, 1)
 
Rather than using Call OpenAccessDatabase, run a batch/cmd file that does the renaming as per my previous suggestions.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
His logic "is through another Access file", I would assume after he closes the 'main' Access database that he wants to rename. Am I correct?

What I don't get is: "extension are changed so as not to [red]steal it[/red]"
Who is going to steal your file from your hard drive [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
When running the patch file through the Access file while it is closed, it does not do what is required, and the file remains without changing its name and extension.
 
I assume your “patch file” was actually a batch file. Can you share the text of the batch file so we know what you tried?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
ameedoo3000 said:
I save it on the hard disk without an extension, so as not to steal it on it, and when I want to use it
So why not run it directly from hidden place?
Code (in Excel, but can be any application that supports VBA), required reference to Access library:
Code:
Sub OpenAccessDB()
Dim AccessApp As Access.Application
Set AccessApp = New Access.Application
With AccessApp
    .Visible = True
    .OpenCurrentDatabase "Path_and_database_name_here"
End With
Set AccessApp = Nothing
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top