473,386 Members | 1,828 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,386 software developers and data experts.

Adding linked table with VBA

Is there way to use VBA to link to an Excel spreadsheet?

I tried to add a new tdf to the xls file but couldn't add the tdf without
also creating field and when I created a field, the table was a local table
and I couldn't set the connect string to make it a linked table.


Nov 13 '05 #1
1 12084
Bri

Karl Irvin wrote:
Is there way to use VBA to link to an Excel spreadsheet?

I tried to add a new tdf to the xls file but couldn't add the tdf without
also creating field and when I created a field, the table was a local table
and I couldn't set the connect string to make it a linked table.


Take a look at the CreateTableDef Method in Help for more detail.
This function works:

Function LinkExcel() As Boolean
On Error GoTo Err_
Dim myDB As DAO.Database, tbl As TableDef
Dim stSource As String, stConnect As String

Set myDB = CurrentDb()
stSource = "Sheet1$"
stConnect = "Excel 5.0;HDR=YES;IMEX=2;DATABASE=C:\myFolder\MySheet.xl s"

Set tbl = myDB.CreateTableDef("mySheet")
tbl.Connect = stConnect
tbl.SourceTableName = stSource

myDB.TableDefs.Append tbl

LinkExcel = True

Exit_:
Set tbl = Nothing
Set myDB = Nothing
Exit Function

Err_:
LinkExcel = False
MsgBox Err.Description
Resume Exit_

End Function


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Eden | last post by:
I havent done any Access database design since doing A-Levels at college, that was 5 to 6 years ago. Now i have to design one for work and I have hit problems. Basically my database has a number...
1
by: Richard Hollenbeck | last post by:
I'm getting errors. Access is telling me that it can't add a record. I have a table of college courses and a linked table of groups of activities in that course as a linked table (one course to...
1
by: Mike Ridley | last post by:
I am trying to create a new query using 3 linked tables. As soon as I add the third table to the design grid Access crashes. I have looked in the newsgroup and find that there have been problems...
2
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only...
8
by: k | last post by:
Hi all I split a database in a table-part and a all-the-rest-part and linked the tables, but my code adding records to a table crashes on Set rs = db.OpenRecordset("tblDeltakelse",...
2
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a...
3
by: ET | last post by:
I don't know whats the problem, but after I added functions to first verify, then relink linked tables if not found, now I can't convert that database to MDE format. I can split the database, but...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
1
by: A | last post by:
Hi I use the following to add a column. This does not work on a linked table. Error: Cannot execute data definition statements on linked data sources. Any ideas ? Thanks Alfred Dim cmd As New...
3
by: menkenk | last post by:
Hello, I created a form with multiple tabs. They are labeled as Info, Policy, Riders. The Info Tab is linked to the Client Information Table, the Policy tab is linked to the Client Policy...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.