Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2006, 10:39 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA to change source of link table

Hi,

I am trying to write a macro that changes the source of a link table. I have tried the code below, but am getting error 3420 "object invalid or no longer set". I can't seem to do anything with the object td at all. Can anyone tell me what I am doing wrong? the table test does already exist.

Thanks

Dim td As TableDef
Set td = CurrentDb.TableDefs("test")
td.Connect = "Text;DSN=Test Link Specification;FMT=Delimited;HDR=NO;IMEX=2;Characte rSet=850;DATABASE=C:\;TABLE=test#txt"
td.RefreshLink
Set td = Nothing
 
Old March 19th, 2006, 01:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Don,

This line:

Code:
Set td = CurrentDb.TableDefs("test")
isn't instantiating a valid TableDef I believe because you havn't instatiated a valid DB object first. The following works for me:

Code:
Sub Test()
    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Set db = CurrentDb
    Set td = db.TableDefs("test")
    td.Connect = "Text;DSN=Test Link Specification;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=850;DATABASE=C:\;TABLE=test#txt"
    td.RefreshLink
    Set td = Nothing
End Sub
The link to the text file is refreshed successfully.

HTH,

Bob

 
Old March 19th, 2006, 01:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

If you run your code an take a peek at the locals window, you'll see that no database variable is created. If you run my code and do the same, a database variable gets created first, then the tabledef is added to the database variables tabledef collection.

Bob

 
Old March 19th, 2006, 05:25 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much! That has solved the problem. Seems I'd missed out part of the code, after trying to bodge together various bits of info I had found around the web.

Also.. had never discovered the Locals window before... interesting

Thanks again,

Don

 
Old March 19th, 2006, 06:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Your welcome Don. The Locals Window simply displays all the local variables that are in scope as your code executes. I always have it open. Its a really useful aid for visualizing what your code is up to at any given moment. Glad things are working for you.

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Link a text file to Access using VBA wscheiman Access VBA 1 June 30th, 2013 07:02 PM
SOLVED - VBA Help For Row Source and Record Source eusanpe Access VBA 4 May 13th, 2008 11:58 AM
change link color swastikagaur Classic ASP Basics 1 March 11th, 2005 10:35 PM
Link Tables thru VBA Rchanga Access 1 November 20th, 2004 11:06 AM
How can I change the shape/color of a button/link elisabeth Javascript How-To 21 September 24th, 2004 05:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.