473,499 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA to auto Refresh Linked Table Manager or linked tables

57 New Member
Hello Everyone,

I was wondering if anyone knows of a way to add a code that would automatically refresh link tables upon opening of database. This is needed due to fact that sometimes split forms wouldn't open due to a lagg and would freak out the user with the error.

The fix was to refresh linked tables manually.

THanks./

-AF
Apr 8 '15 #1
8 36644
jforbes
1,107 Recognized Expert Top Contributor
This might be what you are looking for: http://bytes.com/topic/access/insigh...bles-using-vba

I think I used NeoPa's example above to come up with this:
Expand|Select|Wrap|Line Numbers
  1. Public Function RefreshLinks(ByVal sDatabase As String) As Boolean
  2. On Error GoTo ErrorOut
  3.  
  4.     'Refresh table links to a backend database
  5.  
  6.     Dim dbs As Database
  7.     Dim tdf As TableDef
  8.     Dim sCurrentTDF As String
  9.  
  10.     ' Loop through all tables in the database.
  11.     Set dbs = CurrentDb
  12.     For Each tdf In dbs.TableDefs
  13.         ' If the table has a connect string, it's a linked table.
  14.         If Len(tdf.Connect) > 0 Then
  15.             tdf.Connect = "ODBC;Driver={SQL SERVER};" & "Server=DBSERVER\DB1;" & "Database=" & sDatabase & ";" & "Trusted_Connection=no;" & "Uid=sa;" & "Pwd=secret"
  16.             Err = 0
  17.             On Error Resume Next
  18.             sCurrentTDF = tdf.Name
  19.             tdf.RefreshLink ' Relink the table.
  20.             If Err <> 0 Then
  21.                 RefreshLinks = False
  22.                 Exit Function
  23.             End If
  24.         End If
  25.     Next tdf
  26.  
  27.     RefreshLinks = True
  28. ExitOut:
  29.     Exit Function
  30. ErrorOut:
  31.      msgBox ("There was an error refreshing the link(s) for '" & sCurrentTDF & "':  " & vbCrLf & vbCrLf & Err.Description)
  32.      Resume ExitOut
  33. End Function
I run this from a Form that supplies the Database to relink to. It comes in handy during deployment to switch the Backend Database from a Development Database to a Production Database
Apr 8 '15 #2
aflores41
57 New Member
Thank you jforbes. Do I need that pwd=secret statement? I dont use password on my db.

Once again, thank you.

AF
Apr 9 '15 #3
jforbes
1,107 Recognized Expert Top Contributor
I'm not 100% sure what you would do for a blank password, probably include the parameter but pass a blank string, I think like this:
Expand|Select|Wrap|Line Numbers
  1.             tdf.Connect = "ODBC;Driver={SQL SERVER};" & "Server=DBSERVER\DB1;" & "Database=" & sDatabase & ";" & "Trusted_Connection=no;" & "Uid=sa;" & "Pwd="
For your reference, here are some other examples of a Connection Strings: https://www.connectionstrings.com/mi...r-odbc-driver/
Apr 9 '15 #4
zmbd
5,501 Recognized Expert Moderator Expert
aflores41
if NOT using SQL server then the code J gave you can be simplified.
Apr 9 '15 #5
jforbes
1,107 Recognized Expert Top Contributor
Ah, nice catch Z. I've got some tunnel vision going on. =)
Apr 9 '15 #6
aflores41
57 New Member
Thanks. The code is not working for me though. I'm not linking to SQL Server just to the backend access data.

Any suggestions?

Thanks.

-AF
Apr 13 '15 #7
Seth Schrock
2,965 Recognized Expert Specialist
This article might be of some help, particularly post #2: Relinking Tables using VBA.
Apr 13 '15 #8
jforbes
1,107 Recognized Expert Top Contributor
I apologize for taking you down a path that you didn't need to travel. I primarily use Access as a Frontend and SQL as a Backend, so when you asked about linking, I forgot to keep in mind that there are multiple ways and reasons to link to a database.

You'll want to pretty much forget what I posted as it is skewed towards SQL.

I think this is what you are looking for: http://allenbrowne.com/ser-13.html I haven't used this code, but it looks like the right approach.

...Or the Article Seth has posted =)
Apr 13 '15 #9

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

Similar topics

2
9416
by: Bruce | last post by:
Greetings! After finally figuring out that the Linked Table manager is no longer an add-in in Access 2003 I now discover that it does not display any of my linked tables in the 'select linked...
2
6230
by: Ian Davies | last post by:
Does anyone know how to open the linked table manager using VBA code behind a comand button in Access2000 Ian
2
4299
by: Wayne | last post by:
I've just performed a reformat and reinstalled Access 2000 and 2003 and as usual the linked table manager in Access 2003 is broken ie. it doesn't show any tables. I've gone through the process of...
1
2377
by: steph | last post by:
Hi, I've got a problem. (Microsoft Access 2002 SP3) One of our users found a problem in a when accessing a form with a subform: when starting it access crashes leaving the message...
3
9789
by: sj | last post by:
I have written an application (CW.mde) with a seperate data (Data.mda) file. My Data tables are linked to CW. I want my user to be able to re-link the data.mda when they change location/path of...
7
4746
JodiPhillips
by: JodiPhillips | last post by:
Hi, My first post! I've basically taught myself Access and the little I know about VBA through reading these forums and a couple of books. I'm in the middle of a project at work - to put it...
2
15589
nico5038
by: nico5038 | last post by:
Access 2007 Linkedtable manager refuses to relink tables having a field with the "Attachment" datatype. Problem: When placing a split database in another folder, the Linked table manager should...
1
1504
by: Davidsm | last post by:
Hi Guys Please can you assist me I have created a ODBC link to a sql server and linked tables from sql the problem is in the linked manager it does not show any tables linked. Under the tables...
1
7560
by: franc sutherland | last post by:
Hello, I have a client who uses Access 97, but does not have the Linked Table Manager. The system is split into front and back end. Is it possible to install the Linked Table Manager into...
0
7134
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
7012
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...
1
6901
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
5479
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,...
1
4920
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...
0
4605
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...
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
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...

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.