473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

How to change BackEnd Database links. (Access 2003)

344 Expert 100+
I'm sure many of you use backend and frontend databases. The backend holds all the tables, the frontend holds all the code.

If you are developing for a multi-user system, you may have the same problem I have. As the developer, my front and back end and mdw security file are on my C: drive.

Then end users need the back end, and the security file on the Z: drive (or H: or whatever)

With dozens of tables to swap each time I sent new code out, I needed to do this automaticaly, so I wrote the following bit of code.

This works in Access 2000 and 2003, not sure about Access 2010.

First, I have a simple form, "fdlgDropAll" that has two options.

It allows me to drop all attached tables, or it allows me to change the attachment from one drive to another.

This form has 3 text boxes that display

path for live code
path for live data
path for live mdw

then a button to 'drop all'

and 3 boxes that ask for
drive for live data
drive for live code
drive for live mdw

finally a button to activate change, and a close button.

Ok, so how does it work?

First, I have a module called basConstants that stores, amongst other things, the expected path of the various files. This is used on startup so that I don't accidently send a database out to Africa or India pointing to the wrong files.

basConstants holds the following
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Global Const LIVECODE = "c:\bissau\BissauCode.mdb"
  5. Global Const LIVEDATA = ";DATABASE=z:\Bissau\BissauData.mdb"
  6. Global Const LIVEMDW = "z:\bissau\bissau.mdw"
  7.  

in the on-open event of the form I have the following
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. On Error GoTo Form_Open_Err
  3. LCode = LIVECODE
  4. LData = LIVEDATA
  5. LMDW = LIVEMDW
  6. Form_Open_Exit:
  7.    Exit Sub
  8. Form_Open_Err:
  9.    MsgBox Err.Description & " in Form_Open"
  10.    Resume Form_Open_Exit
  11. End Sub
  12.  
so the form opens, showing you the current links..

NEXT

DropAll is very simple, it will drop all links to attached tables, here is the code for it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDropAll_Click()
  2. On Error GoTo cmdDropAll_Click_Err
  3. Dim db As Database
  4. Dim td As TableDef
  5. Dim i As Integer, j As Integer, var As Variant
  6.  
  7. Dim strAttach As String
  8. Set db = CurrentDb
  9. For i = 0 To db.TableDefs.Count - 1
  10.     Set td = db.TableDefs(i)
  11.     strAttach = td.Connect
  12.     If Len(strAttach & "") > 0 Then
  13.         db.Execute "DROP TABLE " & td.Name & ";"
  14.     End If
  15. Next
  16. Set td = Nothing
  17. Set db = Nothing
  18. MsgBox "All Tables Dropped"
  19. cmdDropAll_Click_Exit:
  20.    Exit Sub
  21. cmdDropAll_Click_Err:
  22.   MsgBox Err.Description & " in cmdDropAll_Click"
  23.    Resume cmdDropAll_Click_Exit
  24. End Sub
  25.  
Next

Now to the nice bit, to re-attach to another drive. This is 'Activate Change'
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdChangeDrive_Click()
  2. On Error GoTo cmdChangeDrive_Click_Err
  3. Dim db As Database
  4. Dim td As TableDef
  5. Dim i As Integer, j As Integer, var As Variant
  6. Dim strAttach As String
  7. Dim strNewAttach As String
  8. Dim strNewCode As String
  9. Dim strNewMDW As String
  10.  
  11. Dim mdl As Module
  12. Dim intLine As Integer, strLine As String
  13.  
  14. strNewCode = NewLiveCode & Right(LCode, Len(LCode) - 1)
  15.  
  16. strNewAttach = Left(LData, 10) & NewLiveData & Right(LIVEDATA, Len(LIVEDATA) - 11)
  17.  
  18. strNewMDW = NewLiveMDW & Right(LMDW, Len(LMDW) - 1)
  19.  
  20.         DoCmd.OpenModule "basConstants"
  21.         ' Return reference to Module object.
  22.         Set mdl = Modules("basConstants")
  23.  
  24.         For intLine = 1 To mdl.CountOfDeclarationLines
  25.         strLine = mdl.Lines(intLine, 1)
  26.         If InStr(strLine, "LIVECODE") > 0 Then
  27.             mdl.ReplaceLine intLine, "Global Const LIVECODE = " & Chr(34) & strNewCode & Chr(34)
  28.         End If
  29.         If InStr(strLine, "LIVEDATA") > 0 Then
  30.             mdl.ReplaceLine intLine, "Global Const LIVEDATA = " & Chr(34) & strNewAttach & Chr(34)
  31.         End If
  32.         If InStr(strLine, "LIVEMDW") > 0 Then
  33.             mdl.ReplaceLine intLine, "Global Const LIVEMDW = " & Chr(34) & strNewMDW & Chr(34)
  34.         End If
  35.         Next
  36.         DoCmd.Close acModule, "basConstants", acSaveYes
  37. Set db = CurrentDb
  38. For i = 0 To db.TableDefs.Count - 1
  39.     Set td = db.TableDefs(i)
  40.     strAttach = td.Connect
  41.     If Len(strAttach & "") > 0 Then
  42.         td.Connect = strNewAttach
  43.         td.RefreshLink
  44.     End If
  45. Next
  46. Set td = Nothing
  47. Set db = Nothing
  48. MsgBox "All Tables Changed"
  49. cmdChangeDrive_Click_Exit:
  50.    Exit Sub
  51. cmdChangeDrive_Click_Err:
  52.    MsgBox Err.Description & " in cmdChangeDrive_Click"
  53.    Resume cmdChangeDrive_Click_Exit
  54. End Sub
  55.  
Thus, this simple form allows me quickly to change my c: drive development code to the multi-user Z: drive code, without the hassle of manually dropping dozens of tables and re-linking, maybe forgetting one table, or maybe deleting one local table. A task I have to do 2-3 times a week on multiple databases.

Hopefully tomorrow I can attach a sample database with all the code in it.

Again, this is written in Access 2003.

Attached is an Access 2003 database with the form fdlgDropAll containing all the code from above.
Attached Files
File Type: zip LinkingCode.zip (20.6 KB, 433 views)
Feb 17 '11 #1
0 7999

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

Similar topics

5
by: j.mandala | last post by:
Someone is trying to run my Access 2002 database under Access 2003. He has had a number of problems: 1) i used the MSComCt2.ocx for it's Date and Time picker. I can't find it under 2003. Do I...
2
by: Jeff | last post by:
Does anyone know of any potential problems running a 2000 database with 2003? Also, what about installing all other Office products as 2003 versions but leaving Access as 2002 running a 2000...
0
by: tdmailbox | last post by:
I developed an access database in access 2003(keeping my database in the access 2000 format). It has been fully tested to be access 2000 compatible and works great. I am trying to package the...
3
by: Susan Bricker | last post by:
I just purchased a new PC that came with MS Office 2003 (Professional Ed.). I opened MS Access 2003 and created a new database but it opened with a "note in the window header bar" that says...
5
by: DeanL | last post by:
I know you can convert a database from Access 2003 to 97 easily but is there anything that I should avoid doing in Access 2003 that might make my database incompatible with Access 97? Many...
1
by: nosipho | last post by:
Hi guys, I want to upgrade to Office 2003/ 2007 Pro, currently I'm using Office 2000. the problem is I have an Access database which I'm not sure if I'll be able to access it with Office 2003/...
3
by: Robert | last post by:
I understand that new features would not be available but is there any way I could open an accdb database in Access 2003? Robert
4
by: azjazz | last post by:
Hi - I tried to search the forums on this issue, but couldn't get good results. I'm sure this has been asked before, so hopefully it won't be too hard to find an answer ... I have a database...
3
by: cwoll | last post by:
I have a Database that I am trying to run on a new vista computer. Up to now I was running it on a win 98 computer and using access 2003! I installed access 2003 and I can make it run and view the...
9
by: Moor | last post by:
I have a .MDB back-end database that is created with Access 2.0. And multiple front-end mdb's, some are created by Access 2.0, and the rest are created by Access 2003. The fron-ends had table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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.