473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to find current backend file and rename it with VBA

547 512MB
Some of clients have an backend linked file that needs to be renamed. This file is not the same for my different clients.
What i have in mind is to use VBA to find the current backend file name (only one file), and then rename it to something else.
These backends files all start with "RacetimeDataV6.1Lic....accdb"(the dots is a licencenumber).It must now be called "RacetimeDatav6.4.accdb".Some of my newer clients already have the renamed file, and the code must then ignore it.
This "wrong" file will be in the C:\RT directory.

My new plan
After opening the startupform, they press a button which then searches for any "Racetimedatav6.4Lic....accdb" file in the c:\RT directory, and rename it to RacetimeDatav6.4.accdb.
The frontend will then have to be closed and re-opened, to link to new "re-named" BE file.
Is it possible?
Sep 11 '11 #1
8 5680
nico5038
3,080 Expert 2GB
I've made a "general" re-link function, as all my back-ends are stored in the same folder as the front-end.

Expand|Select|Wrap|Line Numbers
  1. Function fncRelink()
  2. 'function to relink tables to the "_be" database
  3. 'It's assumed that the "_be" database is in the same folder as the frontend !
  4.  
  5. Dim td As DAO.TableDef
  6.  
  7. For Each td In CurrentDb.TableDefs
  8.   If Len(td.Connect) > 0 Then
  9.      td.Connect = ";DATABASE=" & Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & Mid(td.Connect, InStrRev(td.Connect, "\") + 1)
  10.      td.RefreshLink
  11.   End If
  12. Next
  13.  
  14. MsgBox "Ready, tables relinked"
  15.  
  16. End Function
  17.  
Al you need is "hard-coding" the new location in the .connect and you have solved the re-link. A test for the present .connect value being the new location can be used to skip the re-link.

Getting the idea?

Nic;o)
Sep 11 '11 #2
NeoPa
32,556 Expert Mod 16PB
Why wait for a button to be pressed? Trigger the process on startup of the database.

Find the file first. Then rename it.

When that's been done, use the logic in Nico's code to redo all the matching links and refresh them in place. Once that has been accomplished (and you can include an informative MessageBox call in there wherever you want) the database will continue forward working exactly as you intend (and the user hasn't even been disturbed by the process).
Sep 11 '11 #3
neelsfer
547 512MB
Good idea but how do i find and rename the existing file with VBA? I was stupid enough to customize the BE file for my first few clients, and now its a pain having to customize updates of the FE for them, as they are technologically disadvantaged and struggle with the Linked table manager!(i also feel like that some days)
The BE is in the same directory as the FE = c:\RT
Every one of those client's files start with "RacetimeDatav6.1Lic..." Only the last part differs and it must become "RacetimeDataV6.4.accdb". Any suggestions how to accomplich that?
Sep 11 '11 #4
NeoPa
32,556 Expert Mod 16PB
Sorry. I expected that to be the easy bit.

You either have a known linked table, or all linked tables, that are linked to the BE database. The .Connect property of a linked table contains the full path to that database. That's where the file is that needs to be renamed. The rename command in VBA is the Name statement. You can use a For Each loop in your code to process through the TableDefs collection for all matching linked tables.

Does that make it all clearer? Please say if there's anything still confusing.
Sep 11 '11 #5
neelsfer
547 512MB
Neopa i still have to learn what you have forgotten!

If it was a straightforward rename, then its easy
Expand|Select|Wrap|Line Numbers
  1. Sub DoRename()
  2. Name "c:\RT\RacetimeDatav6.1Lic105.accdb" As "c:\RT\RacetimeDatav6.4.accdb"
  3. End Sub
but now i have to identify the unknown "RacetimeDatav6.1Lic" without the "105" (as above) and then rename it to "RacetimeDatav6.4.accdb"

This part "RacetimeDatav6.1Lic" is the same for all these clients.
This is why i am stuck!
Sep 11 '11 #6
NeoPa
32,556 Expert Mod 16PB
The answer's there Neels. In post #5 already.

If you post the name of one of your linked tables that you know is linked to the original file then I'll knock up some code for you to enable you to determine the full name of the original file. Actually, as the name is just one element of it I'll just use a Constant in the code :

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. Private Const conTblName As String = "tblLinked"  'Enter your table name here
  5.  
  6. Private Function BEName() As String
  7.     Dim varX As Variant
  8.  
  9.     With CurrentDb.TableDefs(conTblName)
  10.         For Each varX In Split(.Connect, ";")
  11.             If varX Like "DATABASE=*" Then
  12.                 BEName = Split(varX, "=")(1)
  13.                 Exit For
  14.             End If
  15.         Next varX
  16.     End With
  17. End Function
Sep 11 '11 #7
I don't think you're going to be able to rename the back-end file if it is open (I.e.: if someone is connected to it from a front-end). You may need a utility application that does the renaming.

You can find the back-end full path by getting the connect string from a table that you know is connected:

Expand|Select|Wrap|Line Numbers
  1. dim MyConnectString as string
  2. dim MyFullPath as string
  3. MyConnectString = CurrentDB().TableDefs("MyTableName").connect
  4. MyFullPath = right(MyConnectString,len(MyConnectString) - len("Database;"))
Sep 14 '11 #8
NeoPa
32,556 Expert Mod 16PB
PDEBaets:
I don't think you're going to be able to rename the back-end file if it is open (I.e.: if someone is connected to it from a front-end).
That's a good point, worth making, but not entirely true. Only if a linked table is actually open will the BE database be locked to a rename (Hence the code posted in post #7 actually works).
Sep 14 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: vishal | last post by:
hi how can i get the file name from which the current executing file is called. i m making a scrript which will be called from many other scripts. this script performs some calculation and then...
4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
1
by: Rob R. Ainscough | last post by:
I'm using VS 2003 VB.NET IDE and the Find (Ctrl+F) function is not working when I select "Search Current Project" -- it will only search the current open file not all the files in the project. ...
0
by: Saloni | last post by:
I have windows service which is going to run on several machines which are in different time zones in USA. I want to find out the Eastern Zone current time from these different machines. It...
0
by: JM | last post by:
Hi, I have uploaded an application written in asp.net 2.0 on server. By web controls started giving Javascript error and I figured it out from discussion groups that I have to put WebForms.js...
7
by: Dave | last post by:
Hi, i need to get the name of the current aspx file in code-behind. Assume the current aspx file is "myfile.aspx", i want to put value "myfile" into a variable in code-behind. Is that possible?...
17
by: fl | last post by:
Hi, I am learning C++ from the following C++ website, which has some very good small examples. For the second Fraction example, which has five files: Main.cpp Fraction.cpp Fraction.h...
13
by: thomas.mertes | last post by:
Hello Recently I discovered some problem. I have some C code which determines how many bytes are available in a file. Later I use this information to malloc a buffer of the correct size before...
2
by: plaguna | last post by:
I have MS Access 2007 (My Database files are saved as .mdb extension). I have no problem to create Users and Groups, and grant them specific Permissions. What I don’t understand is why when I create...
4
viktorijakup
by: viktorijakup | last post by:
Hi !!! @rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" ==...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.