Hi all,
I'm calling a slightly modified Dev Ashish's fRefreshLinks as part of handling an error on opening the switchboard if the backend linked tables are missing. It's Access 2007.
I found a two line tweak online to enable the function to handle passwords, however, after implementing this I'm running into a strange error where the variable strTbl is having "MS Access" appended to it. The exact error message I am getting is:
"Table 'tblTitlesMS Access' was not found in the database C:\Correct\Path\And\DB\Name.accdb. Couldn't refresh links" Note: strTbl = "tblTitlesMS Access")
The correct table name would be 'tblTitles'. There is no instance of "MS Access" in the code, so this must be coming from somewhere else. I suspect this code would be working if it wasn't for this mysterious excess Access
Following is the exact code I currently have. Hopefully somebody here is already familiar with it, I wouldn't expect anybody to digest it from scratch. I have emboldened my own tweaks as well as instances of strTbl - the offending variable - and the error handler being invoked.
I pretty much understand how the code works and follow the logic, but I don't know enough about the underlying processes in linking tables to pinpoint the cause of this.
Any ideas would be much appreciated.
Thanks,
Jay -
'*************** Code Start ***************
-
' This code was originally written by Dev Ashish.
-
' It is not to be altered or distributed,
-
' except as part of an application.
-
' You are free to use it in any application,
-
' provided the copyright notice is left unchanged.
-
'
-
' Code Courtesy of
-
' Dev Ashish
-
'
-
Function fRefreshLinks(strPrompt As String) As Boolean
-
Dim strMsg As String, collTbls As Collection
-
Dim i As Integer, strDBPath As String, strTbl As String
-
Dim dbCurr As Database, dbLink As Database
-
Dim tdfLocal As TableDef
-
Dim varRet As Variant
-
Dim strNewPath As String
-
Dim cPassword As String
-
-
Const cERR_USERCANCEL = vbObjectError + 1000
-
Const cERR_NOREMOTETABLE = vbObjectError + 2000
-
-
On Local Error GoTo fRefreshLinks_Err
-
-
'Prompt User
-
If MsgBox(strPrompt, vbQuestion + vbYesNo, "Alternate data source...") = vbYes Then
-
strNewPath = fGetMDBName("Please select a new datasource")
-
Else
-
Err.Raise cERR_USERCANCEL
-
End If
-
-
'Get Password
-
cPassword = InputBox("Please enter your backend password:", "Enter Password.")
-
-
'First get all linked tables in a collection
-
Set collTbls = fGetLinkedTables
-
-
'now link all of them
-
Set dbCurr = CurrentDb
-
-
For i = collTbls.Count To 1 Step -1
-
strDBPath = fParsePath(collTbls(i))
-
strTbl = fParseTable(collTbls(i))
-
varRet = SysCmd(acSysCmdSetStatus, "Now linking '" & strTbl & "'....")
-
If Left$(strDBPath, 4) = "ODBC" Then
-
'ODBC Tables
-
'ODBC Tables handled separately
-
' Set tdfLocal = dbCurr.TableDefs(strTbl)
-
' With tdfLocal
-
' .Connect = pcCONNECT
-
' .RefreshLink
-
' collTbls.Remove (strTbl)
-
' End With
-
Else
-
If strNewPath <> vbNullString Then
-
'Try this first
-
strDBPath = strNewPath
-
Else
-
If Len(Dir(strDBPath)) = 0 Then
-
'File Doesn't Exist, call GetOpenFileName
-
strDBPath = fGetMDBName("'" & strDBPath & "' not found.")
-
If strDBPath = vbNullString Then
-
'user pressed cancel
-
Err.Raise cERR_USERCANCEL
-
End If
-
End If
-
End If
-
-
'backend database exists
-
'putting it here since we could have
-
'tables from multiple sources
-
'Set dbLink = DBEngine(0).OpenDatabase(strDBPath) ' Original
-
Set dbLink = DBEngine(0).OpenDatabase(strDBPath, False, True, ";pwd =" & cPassword) ' With Password
-
'
-
'check to see if the table is present in dbLink
-
strTbl = fParseTable(collTbls(i))
-
If fIsRemoteTable(dbLink, strTbl) Then
-
'everything's ok, reconnect
-
Set tdfLocal = dbCurr.TableDefs(strTbl)
-
With tdfLocal
-
'.Connect = ";Database=" & strDBPath ' Original
-
.Connect = ";Database=" & strDBPath & ";PWD=" & cPassword ' With Password
-
.RefreshLink
-
collTbls.Remove (.Name)
-
End With
-
Else
-
Err.Raise cERR_NOREMOTETABLE
-
End If
-
End If
-
Next
-
fRefreshLinks = True
-
varRet = SysCmd(acSysCmdClearStatus)
-
MsgBox "All Access tables were successfully reconnected.", _
-
vbInformation + vbOKOnly, _
-
"Success"
-
-
fRefreshLinks_End:
-
Set collTbls = Nothing
-
Set tdfLocal = Nothing
-
Set dbLink = Nothing
-
Set dbCurr = Nothing
-
Exit Function
-
fRefreshLinks_Err:
-
fRefreshLinks = False
-
Select Case Err
-
Case 3059:
-
-
Case cERR_USERCANCEL:
-
MsgBox "No Database was specified, couldn't link tables.", _
-
vbCritical + vbOKOnly, _
-
"Error in refreshing links."
-
Resume fRefreshLinks_End
-
Case cERR_NOREMOTETABLE:
-
MsgBox "Table '" & strTbl & "' was not found in the database" & _
-
vbCrLf & dbLink.Name & ". Couldn't refresh links", _
-
vbCritical + vbOKOnly, _
-
"Error in refreshing links."
-
Resume fRefreshLinks_End
-
Case Else:
-
strMsg = "Error Information..." & vbCrLf & vbCrLf
-
strMsg = strMsg & "Function: fRefreshLinks" & vbCrLf
-
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
-
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
-
MsgBox strMsg, vbOKOnly + vbCritical, "Error"
-
Resume fRefreshLinks_End
-
End Select
-
End Function
-
-
Function fIsRemoteTable(dbRemote As Database, strTbl As String) As Boolean
-
Dim tdf As TableDef
-
On Error Resume Next
-
Set tdf = dbRemote.TableDefs(strTbl)
-
fIsRemoteTable = (Err = 0)
-
Set tdf = Nothing
-
End Function
-
-
Function fGetMDBName(strIn As String) As String
-
'Calls GetOpenFileName dialog
-
Dim strFilter As String
-
-
strFilter = ahtAddFilterItem(strFilter, _
-
"Access Database(*.mdb;*.mda;*.mde;*.mdw) ", _
-
"*.mdb; *.mda; *.mde; *.mdw")
-
strFilter = ahtAddFilterItem(strFilter, _
-
"All Files (*.*)", _
-
"*.*")
-
-
fGetMDBName = ahtCommonFileOpenSave(Filter:=strFilter, _
-
OpenFile:=True, _
-
DialogTitle:=strIn, _
-
Flags:=ahtOFN_HIDEREADONLY)
-
End Function
-
-
Function fGetLinkedTables() As Collection
-
'Returns all linked tables
-
Dim collTables As New Collection
-
Dim tdf As TableDef, db As Database
-
Set db = CurrentDb
-
db.TableDefs.Refresh
-
For Each tdf In db.TableDefs
-
With tdf
-
If Len(.Connect) > 0 Then
-
If Left$(.Connect, 4) = "ODBC" Then
-
' collTables.Add Item:=.Name & ";" & .Connect, KEY:=.Name
-
'ODBC Reconnect handled separately
-
Else
-
collTables.Add Item:=.Name & .Connect, Key:=.Name
-
End If
-
End If
-
End With
-
Next
-
Set fGetLinkedTables = collTables
-
Set collTables = Nothing
-
Set tdf = Nothing
-
Set db = Nothing
-
End Function
-
-
Function fParsePath(strIn As String) As String
-
If Left$(strIn, 4) <> "ODBC" Then
-
fParsePath = Right(strIn, Len(strIn) _
-
- (InStr(1, strIn, "DATABASE=") + 8))
-
Else
-
fParsePath = strIn
-
End If
-
End Function
-
-
Function fParseTable(strIn As String) As String
-
fParseTable = Left$(strIn, InStr(1, strIn, ";") - 1)
-
End Function
7 2560 NeoPa 32,556
Recognized Expert Moderator MVP
Jay, you need to include some basic information here such as the line the error message occurs on. Otherwise this is a needle in a haystack situation. Please check out Before Posting (VBA or SQL) Code for some more instructns on what needs to be done prior to posting a question about included code.
Your code looks good for me.
In your current database seems to exist (indeed) a table named tblTitlesMS Access.
I suspect that it is hidden (Don't ask me why :) ).
So, in order to debug, do the following:
Navigate to: Office Button -> Access Options -> Current Database -> Navigation Options
and check all check boxes in Display Options area.
After that, in Navigation Pane, look for that table and remove it (if you find it). Make a copy before ! @NeoPa
The code will not stop at this error.
Line #87 will raise the error and the error message is from line #114
Hi Mihail,
An existing table was my first thought, however even on enabling all options, no table by the name of "tblTitlesMS Access" exists. Is there some other way a tabledef could be hidden?
As you predicted, even on commenting out the "On Local Error..." line, the code doesn't throw an error until it reaches line 87. (I had previously tested this, but missed it from my post, apologies Neo).
On placing a debug dot in the Function fParseTable and bringing up strIn in a MsgBox displays:
tblTitlesMS Access;PWD=asdfzxcv;DATABASE=C:\Correct\Path\And\N ame.accdb
This would indeed point to a TableDef by that name existing. However, I have just placed the code... -
Dim x as Integer
-
x = 1
-
For i = collTbls.Count To 1 Step -1
-
If Left(collTbls(i), 9) = "tblTitles" Then
-
i = i - x
-
End If
-
...at the start of the For loop. I then tried assigning various numbers to x and the error is now the same, but with which ever table falls at that number, e.g. "tblStatusMS Access", "tblContactMS Access".
This would point to either a duplication of all tables with MS Access appended to them, or seemingly more likely, that strTbl is having MS Access appended to it before being passed to fParseTable.
Any thoughts?
Thanks again,
Jamie
Is beyond my skill (or my working time) to fully debug your code.
Here is how I manage the "link" issue for a Front End database: - Public Function ReConnect(BackEndPath As String) As Boolean
-
ReConnect = False
-
On Error GoTo ErrorHandler
-
If BackEndPath = "" Then Exit Function
-
-
Dim tbl As TableDef
-
Dim db As Database
-
'(Re)link current Front End database
-
Set db = CurrentDb
-
GoSub RelinkThisFE
-
-
'All is Ok
-
ReConnect = True
-
-
Ex:
-
Exit Function
-
-
RelinkThisFE:
-
With db
-
For Each tbl In .TableDefs
-
If (tbl.Attributes And dbAttachedTable) Then 'This is a linked table
-
With .TableDefs(tbl.Name)
-
.Connect = ";DATABASE=" & BackEndPath
-
Call .RefreshLink
-
End With
-
End If
-
Next
-
Call .Close
-
End With
-
Return
-
-
ErrorHandler:
-
MsgBox ("I think that you have wrong selected the back end database. Try again !")
-
db.Close
-
set db = Nothing
-
Resume Ex
-
End Function
NeoPa 32,556
Recognized Expert Moderator MVP
I would trace through fGetLinkedTables(). I suspect it is creating your collection incorrectly, as it is based on the assumption that any .Connect string that doesn't start with "ODBC" must necessarily start with a ";". There is an .Attributes property that is a better test for that in my view (Check out the difference between dbAttachedTable and dbAttachedODBC).
Sure Mihail, I understand that. I was hoping it was something that would jump out and smack you in the face. Thanks for your solution. I'll have a play with it if I can't fix this one.
You inadvertently gave me a new lead. In unhiding the System objects you showed me the table MSysObjects which includes a Connect field showing "MS Access;PWD=asdfzxcv;". I'm going to play with the code with this in mind. NeoPa, fGetLinkedTables contains the line:
collTables.Add Item:=.Name & .Connect, Key:=.Name
The part in bold would account for the strange concatenation. I just need to tweak it to create a valid connection string, which I should be able to figure out.
Thanks again guys.
NeoPa 32,556
Recognized Expert Moderator MVP
In most cases that will work reliably Jay. The thing to do is to discover the exception (Tracing should help).
I suspect that code amended to use the .Attributes property, instead of the contents of the .Connect property, will handle the situation more reliably.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ashish |
last post by:
I have a svg file which is embeded in HTML file like:
<embed id="svgroomindex"
src="http://in-dev-ashishm/SVG/11roomindex.svg" width="100%"
height="100%" />
I have a javascript function to...
|
by: Mark Cubitt |
last post by:
I have successfully used the excellent InetTransfer written by Dev
Ashish and Terry Kreft to download using http from unprotected web
sites. I need to be able to download from a protected web site...
|
by: Tony |
last post by:
Access collective,
I am running WinNT4.0, Acc2000 SR1 and IE 6.0.
I converted (from Acc97) and imported Dev Ashish's InetTransferLib add-in
modules into my Acc2000 database. Using the sample FTP...
|
by: Lauren Wilson |
last post by:
Hi folks,
I copied Dev Ashish's code below to a module in Access 2K. No mater
what I do, Access will not recognize the function. What have I
overlooked?
I know I'm going to feel like an...
|
by: Ashish Kanoongo |
last post by:
I am getting error at the time of compilation, However application runs successfully
'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'SelectedValue'.
It is giving...
| |
by: Tim::.. |
last post by:
Hi can someone please tell me why I keep getting the following error and how I might fix it
...::ERROR::.
Exception Details: System.Runtime.InteropServices.ExternalException: A generic error...
|
by: Ashish Gupta |
last post by:
Hi Guys
I am using mailing list web service of infoUSA.com.
Sometimes it gives the following error :
System.Web.Services.Protocols.SoapException: Server was unable to process
request. --->...
|
by: Ashish |
last post by:
Hi Guys
I am getting the following error while implementing authentication using WS-security.
"Microsoft.Web.Services2.Security.SecurityFault: The security token could not be authenticated or...
|
by: Ashish |
last post by:
hi all,
I dont know if this is possible or not, but what i want to do is specify
a delegate for an exception
for example iam trying to create a xml document like
Dim objDoc As New XmlDocument...
|
by: Kelii |
last post by:
Hi all,
(WinXP Pro SP2, Access 2003)
I'm using Dev Ashish's fRefreshLinks function from AccessWeb
(http://www.mvps.org/access/tables/tbl0009.htm) to relink tables in my
front end to one of...
|
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,...
| |
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,...
|
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...
|
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...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |