×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

rename current database
2

rename current database

rename current database

(OP)
hi every body
how can i rename my current database after close it automaticly with vba code

RE: rename current database

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

RE: rename current database

(OP)
Is there any solution or trick?

RE: rename current database

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

RE: rename current database

I would like to know - WHY do you want to do it ponder

---- Andy

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

RE: rename current database

(OP)
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?

RE: rename current database

So apparently you won’t share the purpose for this request?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

(OP)
The purpose of changing the file name and extension after completing work on it is to hide it and not steal it

RE: rename current database

You stated "I already did this" but provided little detail on what exactly you tried. I did a simple search of the web and found this thread using /wait.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

(OP)
What is the code when closing an access file (renaming it) using the Start /wait statement?

RE: rename current database

Do a search on "batch file commands" and maybe include "rename".

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

Quote (ameedoo3000)

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

RE: rename current database



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"

Name strPath & strOrgFile As strPath & strNewFile

End Sub 

---- Andy

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

RE: rename current database

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

RE: rename current database

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

RE: rename current database

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

RE: rename current database

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 steal it"
Who is going to steal your file from your hard drive ponder

---- Andy

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

RE: rename current database

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

RE: rename current database

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

RE: rename current database

Quote (ameedoo3000)

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

RE: rename current database

combo,
Could these 2 lines:

CODE

Dim AccessApp As Access.Application
Set AccessApp = New Access.Application 
be done in one line:

CODE

Dim AccessApp As New Access.Application 
ponder

---- Andy

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

RE: rename current database

(OP)
It seems that we have fallen far from the desired goal
Anyway, I will simplify things so that my goals become clear
On my desktop, I have two Access files, file A has no extension, and file B has the extension. All I want is him
1- Open file B through file A after changing its extension.
2- When you close file A, its extension is changed to no extension (automatically) to become as it was.
Is this possible or impossible?

RE: rename current database

I used to instantiate objects in the first way. I've heard that it works faster (after 'As New' declaration, in every call of object VB checks if the object is instantiated) and is safer (test with condition myObject Is Nothing is always false).

combo

RE: rename current database

I tested this batch/cmd file using a link I posted much earlier.

CODE --> RunRename.cmd

@echo off
cd \data\access
REN Wordle.xxx Wordle.accdb

START  /wait "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "c:\data\access\Wordle.accdb"
REN Wordle.accdb Wordle.xxx 

The code will change to the appropriate directory, rename the Access file, run the Access file, wait until the user exits the Access file, and renames the Access file.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

(OP)
Thank you very much, my dear "dhookom".
It was a very perfect solution and exactly what I wanted.. Thank you very much.

RE: rename current database

(OP)
Please.. How can no error message appear in error cases?
For example "file not found" error

RE: rename current database

Spell everything correctly. You could have a different location for your Access file. We can’t tell because you didn’t share anything.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

(OP)
The recommended steps were implemented correctly and what was required was implemented successfully. I thank you for that. But there is a possibility that this file () will be stolen and run on another computer. Then an error message will appear explaining that the path or name of the file has changed, and thus the whole matter will be exposed. Therefore, I would like not to show any error message in the patch file code... That's all. I hope I made it clear

RE: rename current database

Again, it’s “batch”, not “patch”. You should be able to search the web for batch commands to do what you want. I searched to find your solution. I didn’t know anything about the WAIT command prior to reading your question.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: rename current database

(OP)
Thank you for correcting my spelling mistakes. Thank you for your effort

RE: rename current database

Quote (ameedoo3000)

But there is a possibility that this file () will be stolen and run on another computer.
If the file is critical, just password protect the database, so the file will be useless without knowing the password. You will also need a secure copy, to restore data if the file was destroyed/deleted.

combo

RE: rename current database

I remember doing a similar thing in Excel to attempt to make it foolproof for requiring the user to ENABLE MACROS. It takes a lot of thought and knowledge of the properties and methods of objects and Events.

The key was in the Save event, as I recall, to make the application appear to have only ONE useless sheet while all other sheets were very hidden. If the user ENABLED MACROS, the very hidden sheets were made visible. When the application would close, it would make all sheets but one very hidden before saving and closing. Didn't matter where it was saved.

Well one weak spot was that although the VBA was password protected, that could be cracked.

With user-friendly DIY applications like Access or Excel, they are thus vulnerable to tampering. You need an executable to distribute, that you generate from your personal master.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close