473,406 Members | 2,620 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,406 software developers and data experts.

Problem trying to relink back end

204 128KB
I want to distribute my DB to different "departments". Each will have their own BE data (all the same format and structure, but each with their own pwd) and all will use a common FE to access it.

So the plan is to distribute the common FE and a dummy BE, with the string "nulldata" in its name ("...nulldata..."). The nulldata BE has a simple pwd known to the FE when I distribute it. The remote users then copy the dummy BE and rename the copy as "...livedata..." ready to add their own data into it. They then decrypt and re-encrypt their livedata with their own password. I expected they could open the FE (pointing to nulldata) and use my code, with a pwd they supply, to link to their livedata.

But it doesn't work. My code is
Expand|Select|Wrap|Line Numbers
  1. strConnect = "MS Access;PWD=xxx;DATABASE=K:\Emmaus BS testdata_be.accdb"
  2. For Each tbl In CurrentDb.TableDefs
  3.     If InStr(tbl.Connect, Currently) > 0 Then              ' i.e. if it is a linked table (they all are, usually!)
  4.         TableName = tbl.Name & " table: "                  ' Extract table name for possible error message
  5.         tbl.Connect = strConnect                           ' same connect string for all linked tables
  6.     End If
  7. Next tbl 
("Currently" is a string variable containing a string known to exist in the BE file name - in this case, "null").
The code runs to completion, but doesn't change the links; in the navigation pane I see the tables still linked to the original BE.

I tried replacing the tbl.connect line with tbl.refreshlink, but that made no difference.
So I preceded the tbl.connect line with
Expand|Select|Wrap|Line Numbers
  1. DoCmd.DeleteObject acTable, TableName
. That made a difference - I now get Error No. 7874, "Emmaus BS DB can't find the object '~TMPCLP191411'.".

Does anyone know how I can get out of this?
I have no idea what object ~TMPCLP191411 is.
Nov 28 '19 #1

✓ answered by NeoPa

Hi Petrol.

See if this procedure helps. It has links to other modules but there are various concepts illustrated in here that should save you lots of time & effort. I've tried to include the other procedures it references but there may be some omitted.

Linked tables can be identified by their Attributes, as you'll see below :
RelinkTables()
Expand|Select|Wrap|Line Numbers
  1. Public Const conConnect As String = "MS Access;PWD=%P;DATABASE=%D"
  2. 'RelinkTables() ensures that all Jet-linked tables currently linked to
  3. '  strOldPath will be relinked to strNewPath.
  4. Public Function RelinkTables(ByVal strOldPath As String _
  5.                            , ByVal strNewPath As String _
  6.                            , ByVal strPW As String _
  7.                            , Optional ByRef dbVar As DAO.Database _
  8.                            , Optional ByVal blnPW As Boolean = True) As Integer
  9.     Dim tdfVar As DAO.TableDef
  10.  
  11.     On Error Resume Next
  12.     If strNewPath = strOldPath Then Exit Function
  13.     If Not Exist(strNewPath) Then Exit Function
  14.     If dbVar Is Nothing Then Set dbVar = CurrentDb()
  15.     For Each tdfVar In dbVar.TableDefs
  16.         Call Err.Clear
  17.         With tdfVar
  18.             If (.Attributes And dbAttachedTable) Then
  19.                 If InStr(1, .Connect, strOldPath) > 0 Then
  20.                     If blnPW Then
  21.                         .Connect = MultiReplace(conConnect _
  22.                                               , "%P", Scramble(strPW) _
  23.                                               , "%D", strNewPath)
  24.                     Else
  25.                         .Connect = MultiReplace(conConnect _
  26.                                               , "MS Access;PWD=%P", "" _
  27.                                               , "%D", strNewPath)
  28.                     End If
  29.                     Call .RefreshLink
  30.                     If Err = 0 Then RelinkTables = RelinkTables + 1
  31.                 End If
  32.             End If
  33.         End With
  34.     Next tdfVar
  35. End Function
Expand|Select|Wrap|Line Numbers
  1. 'Exist() returns true if strFile exists.  By default ignores folders.
  2. '22/05/2003 Rewritten with better code.
  3. '20/05/2005 Added finding of R/O, System & Hidden files.
  4. '11/12/2012 Added handling of inaccessible drives.
  5. '22/05/2013 Added code to avoid false positives for folders.
  6. Public Function Exist(ByVal strFile As String _
  7.                     , Optional intAttrib As Integer = vbReadOnly _
  8.                                                    Or vbHidden _
  9.                                                    Or vbSystem) As Boolean
  10.     On Error Resume Next
  11.     'Strip trailing "\" characters as this gives a false reading.
  12.     If Right(strFile, 1) = "\" Then strFile = Left(strFile, Len(strFile) - 1)
  13.     Exist = (Dir(PathName:=strFile, Attributes:=intAttrib) <> "")
  14. End Function
Expand|Select|Wrap|Line Numbers
  1. 'MultiReplace() takes each pair of parameters from avarArgs() and replaces the
  2. '  first with the second wherever found in strMain.
  3. 'Using VbBinaryCompare means that case is recognised and not ignored.
  4. '08/05/2013 Updated to support passing of an array directly into avarArgs.
  5. Public Function MultiReplace(ByRef strMain As String _
  6.                            , ParamArray avarArgs() As Variant) As String
  7.     Dim intX As Integer
  8.     Dim avarVals() As Variant
  9.  
  10.     'Code to handle avarArgs passed as an existing array.
  11.     If (UBound(avarArgs) = LBound(avarArgs)) _
  12.     And IsArray(avarArgs(LBound(avarArgs))) Then
  13.         ReDim avarVals(LBound(avarArgs) To UBound(avarArgs(LBound(avarArgs))))
  14.         For intX = LBound(avarVals) To UBound(avarVals)
  15.             avarVals(intX) = avarArgs(LBound(avarArgs))(intX)
  16.         Next intX
  17.     Else
  18.         avarVals = avarArgs
  19.     End If
  20.     If (UBound(avarVals) - LBound(avarVals)) Mod 2 = 0 Then Stop
  21.     MultiReplace = strMain
  22.     For intX = LBound(avarVals) To UBound(avarVals) Step 2
  23.         MultiReplace = Replace(Expression:=MultiReplace, _
  24.                                Find:=Nz(avarVals(intX), ""), _
  25.                                Replace:=Nz(avarVals(intX + 1), ""), _
  26.                                Compare:=vbBinaryCompare)
  27.     Next intX
  28. End Function
NB. It works just as well for ACE as for Jet (-linked tables).

7 1594
NeoPa
32,556 Expert Mod 16PB
The missing link here is :
Expand|Select|Wrap|Line Numbers
  1. Call tbl.RefreshLink()
Give me 5 mins & I'll dig up a module for you that may be helpful.
Nov 29 '19 #2
NeoPa
32,556 Expert Mod 16PB
Hi Petrol.

See if this procedure helps. It has links to other modules but there are various concepts illustrated in here that should save you lots of time & effort. I've tried to include the other procedures it references but there may be some omitted.

Linked tables can be identified by their Attributes, as you'll see below :
RelinkTables()
Expand|Select|Wrap|Line Numbers
  1. Public Const conConnect As String = "MS Access;PWD=%P;DATABASE=%D"
  2. 'RelinkTables() ensures that all Jet-linked tables currently linked to
  3. '  strOldPath will be relinked to strNewPath.
  4. Public Function RelinkTables(ByVal strOldPath As String _
  5.                            , ByVal strNewPath As String _
  6.                            , ByVal strPW As String _
  7.                            , Optional ByRef dbVar As DAO.Database _
  8.                            , Optional ByVal blnPW As Boolean = True) As Integer
  9.     Dim tdfVar As DAO.TableDef
  10.  
  11.     On Error Resume Next
  12.     If strNewPath = strOldPath Then Exit Function
  13.     If Not Exist(strNewPath) Then Exit Function
  14.     If dbVar Is Nothing Then Set dbVar = CurrentDb()
  15.     For Each tdfVar In dbVar.TableDefs
  16.         Call Err.Clear
  17.         With tdfVar
  18.             If (.Attributes And dbAttachedTable) Then
  19.                 If InStr(1, .Connect, strOldPath) > 0 Then
  20.                     If blnPW Then
  21.                         .Connect = MultiReplace(conConnect _
  22.                                               , "%P", Scramble(strPW) _
  23.                                               , "%D", strNewPath)
  24.                     Else
  25.                         .Connect = MultiReplace(conConnect _
  26.                                               , "MS Access;PWD=%P", "" _
  27.                                               , "%D", strNewPath)
  28.                     End If
  29.                     Call .RefreshLink
  30.                     If Err = 0 Then RelinkTables = RelinkTables + 1
  31.                 End If
  32.             End If
  33.         End With
  34.     Next tdfVar
  35. End Function
Expand|Select|Wrap|Line Numbers
  1. 'Exist() returns true if strFile exists.  By default ignores folders.
  2. '22/05/2003 Rewritten with better code.
  3. '20/05/2005 Added finding of R/O, System & Hidden files.
  4. '11/12/2012 Added handling of inaccessible drives.
  5. '22/05/2013 Added code to avoid false positives for folders.
  6. Public Function Exist(ByVal strFile As String _
  7.                     , Optional intAttrib As Integer = vbReadOnly _
  8.                                                    Or vbHidden _
  9.                                                    Or vbSystem) As Boolean
  10.     On Error Resume Next
  11.     'Strip trailing "\" characters as this gives a false reading.
  12.     If Right(strFile, 1) = "\" Then strFile = Left(strFile, Len(strFile) - 1)
  13.     Exist = (Dir(PathName:=strFile, Attributes:=intAttrib) <> "")
  14. End Function
Expand|Select|Wrap|Line Numbers
  1. 'MultiReplace() takes each pair of parameters from avarArgs() and replaces the
  2. '  first with the second wherever found in strMain.
  3. 'Using VbBinaryCompare means that case is recognised and not ignored.
  4. '08/05/2013 Updated to support passing of an array directly into avarArgs.
  5. Public Function MultiReplace(ByRef strMain As String _
  6.                            , ParamArray avarArgs() As Variant) As String
  7.     Dim intX As Integer
  8.     Dim avarVals() As Variant
  9.  
  10.     'Code to handle avarArgs passed as an existing array.
  11.     If (UBound(avarArgs) = LBound(avarArgs)) _
  12.     And IsArray(avarArgs(LBound(avarArgs))) Then
  13.         ReDim avarVals(LBound(avarArgs) To UBound(avarArgs(LBound(avarArgs))))
  14.         For intX = LBound(avarVals) To UBound(avarVals)
  15.             avarVals(intX) = avarArgs(LBound(avarArgs))(intX)
  16.         Next intX
  17.     Else
  18.         avarVals = avarArgs
  19.     End If
  20.     If (UBound(avarVals) - LBound(avarVals)) Mod 2 = 0 Then Stop
  21.     MultiReplace = strMain
  22.     For intX = LBound(avarVals) To UBound(avarVals) Step 2
  23.         MultiReplace = Replace(Expression:=MultiReplace, _
  24.                                Find:=Nz(avarVals(intX), ""), _
  25.                                Replace:=Nz(avarVals(intX + 1), ""), _
  26.                                Compare:=vbBinaryCompare)
  27.     Next intX
  28. End Function
NB. It works just as well for ACE as for Jet (-linked tables).
Nov 29 '19 #3
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. DoCmd.DeleteObject acTable, TableName
You're better off using proper VBA object code than using the pseudo-operator object (DoCmd) wherever & whenever possible. Also, avoid using CurrentDb() directly for anything but the most trivial of uses. It's a function not an object per se. It never returns the same object twice. Very wasteful and causes problems if allowed.
Expand|Select|Wrap|Line Numbers
  1. Dim strTableName As String
  2. Dim dbVar As DAO.Database
  3.  
  4. strTableName = "~TMPCLP191411"
  5. If dbVar Is Nothing Then Set dbVar = CurrentDb()
  6. With dbVar.TableDefs
  7.     Call .Delete(strTableName)
  8.     Call .Refresh()
  9. End With
When you delete tables through your interface the table is only really gone from your view. It still exists in the database, with a new name like the one you have, until the database goes through a Compact & Repair process. It's still held in the TableDefs collection till then.
Nov 29 '19 #4
Petrol
204 128KB
Many thanks for all that, NeoPa. It will take me a while to absorb it! ... but I'll work on my other post, about images, (and thanks also for the reply to that) first.
Nov 29 '19 #5
NeoPa
32,556 Expert Mod 16PB
All good. I'm keen to hear how you get on with it :-)
Nov 29 '19 #6
Petrol
204 128KB
OK. thanks again for your help. All good now.
(I was a bit daunted at first by the sight of 70+ lines of code to replace my half dozen :-), but once I figured them out they were quite instructive in several ways - and they helped me debug my half dozen!)
Nov 30 '19 #7
NeoPa
32,556 Expert Mod 16PB
Hi Petrol.

Yeah. The two extra procedures are simply what I use for convenience, and they take up the majority of the 77 lines. The main logic is in the RelinkTable() procedure and that only has as many as 35 due to my style of continuing lines rather than going beyond column #80. MultiReplace() is one I couldn't do without though. Once you start using it in earnest you realise why.

I didn't include my Scramble() routine for encrypting and decrypting passwords but you're welcome to send me a PM for it if you're interested. It's not ultra secure but it's a way beyond basic. I don't publish it to avoid giving any malicious readers the opportunity to disect and crack it. Otherwise I'm happy to share it though.
Petrol:
once I figured them out they were quite instructive in several ways - and they helped me debug my half dozen!
That's the best news of all. Anyone can use code. Understanding what it does and using that understanding elsewhere is where the benefits really come in. Good for you :-)
Nov 30 '19 #8

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

Similar topics

2
by: David Aldred | last post by:
Hi, I got a script from a site to page results from a db. That all went fine. But I wanted to let the user decide how many per page are viewed. Initially, the number of results per page was set by...
1
by: Michael Eisner | last post by:
I have an MS Access 8.0 (Office97) program that has a form called FO-008 that I need to replace on several users computers in different locations without me being there doing it manually. I'm...
1
by: Magnus | last post by:
I want to generate a report and display it as a pdf in a WebForm (RptForm). To generate the report I need to pass some (sometimes a lot of) parameters from a WebForm (WebForm1). The report looks...
0
by: Paco Ferre | last post by:
Hello, I founded some examples of WebControl printing in internet and tryed to have them working for a DataGrid, something not very complicated. I have a page, Page1.aspx with a DataGrid...
4
by: Heinrich Wolf | last post by:
Hi all I have a history.back() problem with FF(2). IE works as expected, while FF does not. The multi frame website setup as a whole with a lot of frame content switching works flawlessly in...
1
by: =?Utf-8?B?RG9t?= | last post by:
I have been trying to back up my hard drive using Vista's built-in back up. It has worked before but now i keep getting this message.... The backup did not complete successfully. An error...
8
by: Greg C. | last post by:
I tried tackling this problem about 6 months ago, but after going almost completely insane I gave up, since my news feed seemed to display just fine anyways. However, in an effort to have my feeds...
4
by: 2inshix | last post by:
Hello, I'm new to this website. I want to thank everyone here for the wonderful help you are providing to the community. I stated teaching myself programming in python only a few weeks back and...
4
by: Ronald Ocampo | last post by:
Hi, I have a network of five PCs with 4 running Vista Home Basic with the other one running XP. I have an Access 2007 database system wherein the back end is installed in the public folder of one of...
19
by: breakdance89 | last post by:
I have this code which puts correct dates on msflexgrid control for weekly rotas on my program. What it currently does is checks which day is monday and the loops it through creating dates...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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,...

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.