473,564 Members | 2,730 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 36704
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
9450
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 tables to be updated' list. Although I have about 30 linked tables in my application, absolutely none of them are showing up in the list. I compacted...
2
6238
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
4311
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 re-registering Accwiz.dll as outlined in the MS Knowledge Base and although this process has worked for me before, it hasn't worked this time. ...
1
2383
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 "MSACCESS.EXE - Application Error ... The instruction at "..." referenced memory at "...". The memory could not be read". Now if I remove the subform from...
3
9804
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 the data.mda. Hence, I have an button with the following: DoCmd.RunCommand acCmdLinkedTableManager The button works on the computer with Ms...
7
4760
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 mildly I've been thrown in at the deep end, in the past I've just done simple databases and that's been fine. Now, however I have to "roll out" various...
2
15599
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 be used to relink the tables. The Linkedtable manager does however refuse to relink tables having an "Attachment" datatype field. Symptoms: Open...
1
1516
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 tab the tables show but on field in not being populated with the Amount it leaves the column blank but in the sql quert the amount column is populated....
1
7573
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 Access 97? If not, how does one manage the table links? Thanks,
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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. ...
0
7951
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...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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
0
925
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...

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.