473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change BackEnd Database links. (Access 2003)

344 Recognized Expert Contributor
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, "fdlgDropAl l" 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, 434 views)
Feb 17 '11 #1
0 8029

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

Similar topics

5
7844
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 need to send it to them? 2) I have a function to fill a table with values, that store the page and column numbers of a display of staff members. I had him check the link to Microsoft DAO 3.6 Object Library under references, but it still won't...
2
2325
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 database? Why you ask! A client has a 2000 database. Currently using 2000 runtime for most employees to work with database. A couple use 2003 to use database, no problems. They have a mix of versions of other products such as Word, Excel - 97,...
0
444
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 final version however and when I tell it to create a shortcut it includeds the path to access 2003 in the shortcut C:\Program Files\Microsoft Office\OFFICE11\ my client is running access 2000. I could not figure any way to change the access...
3
2931
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 "Access 2000 File Format". 1. Why did this happen? 2. Should I delete this database and start again? 3. I am not exactly sure what level of software the end user will be at (I am creating this database for use by someone else), but I have been...
5
1810
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 thanks, Dean...
1
1989
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/ 2007. So is there anyone who knows about this? Please help ,soon Ragards
3
22619
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
2032
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 created in Access 97 with a lot of VBA code embedded in it. I don't think I will be allowed to convert it to Access 2003, since a lot of users outside of my group still access the database with Access 97. That said, I want to run the Access 97...
3
2545
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 data but I can not save any new records. Has any one seen this problem yet? Thanks Clarence Wollman
9
2402
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 attachments to the back-end database. The problem is I'm unable to access any table by both versions of Access in the same time! Here are the steps to replicate the problem 1- Open one Access 2.0 front-end mdb, then open the attached table T1
0
8251
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.