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

Trouble With Linking To Excel

Hi and HELP!,

I am using Excel and Access 2003. I am trying to create a link to an excel spreadsheet and append the data from a specific sheet called "PEJ". My error is runtime error 3125 "PEJ$" is not a valid name. When I perform these tasks manually it works...any help? Oh, I prefer to link because the spreadsheet data will change quite frequently and I will be performing this function on multiple sheets.

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim tdfLinked As TableDef
  3. Dim strSearchTable, strTableToFind, TempDate As String
  4. Dim myPath As String, myFile As String
  5.  
  6. myPath = "c:\documents and settings\NAME\My Documents\NAME\Excel Analytics\ETFs\"
  7. myFile = "DTC_032707_1"
  8. strTableToFind = "tbl_LINK_" & Me!comboChooseETF
  9. TempDate = Format(Date, "mmddyy")
  10. Set db = CurrentDb
  11. 'strSearchTable = "SELECT COUNT(*) FROM MSYSObjects WHERE (((MSYSObjects.Name)='tbl_LINK_PEJ'));"
  12.  
  13. If TableExists("" & strTableToFind & "") Then
  14.     CurrentDb.TableDefs.Delete ("" & strTableToFind & "")
  15. End If
  16.  
  17. Set tdfLinked = db.CreateTableDef("" & strTableToFind & "")
  18. tdfLinked.Connect = _
  19.     "Excel 5.0;HDR=YES;IMEX=2;DATABASE=" & myPath & myFile & ".xls"
  20. Debug.Print myPath & myFile & ".xls"
  21. tdfLinked.SourceTableName = "PEJ$"
  22. db.TableDefs.Append tdfLinked
  23. DoCmd.RunSQL "SELECT " & strTableToFind & ".ETFSymbol, " & strTableToFind & ".CUSIP, " & strTableToFind & ".ETFName, " & strTableToFind & ".TotalQty, " & strTableToFind & ".LastPrice INTO " & Me!comboChooseETF & "_" & TempDate & _
  24.                             " FROM " & strTableToFind
  25.  
  26. '    DoCmd.RunSQL "DELETE * FROM tbl_LINK_" & Me!comboChooseETF & ";"
  27. db.Close
  28. Set db = Nothing
  29. Set tdfLinked = Nothing
Apr 17 '07 #1
3 1923
maxamis4
295 Expert 100+
I am not to familiar with the link part of excel. I usually just import my records. Try www.utteraccess.com, those guys are more into the module/coding part of different variations of code.

Hi and HELP!,

I am using Excel and Access 2003. I am trying to create a link to an excel spreadsheet and append the data from a specific sheet called "PEJ". My error is runtime error 3125 "PEJ$" is not a valid name. When I perform these tasks manually it works...any help? Oh, I prefer to link because the spreadsheet data will change quite frequently and I will be performing this function on multiple sheets.

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim tdfLinked As TableDef
  3. Dim strSearchTable, strTableToFind, TempDate As String
  4. Dim myPath As String, myFile As String
  5.  
  6. myPath = "c:\documents and settings\NAME\My Documents\NAME\Excel Analytics\ETFs\"
  7. myFile = "DTC_032707_1"
  8. strTableToFind = "tbl_LINK_" & Me!comboChooseETF
  9. TempDate = Format(Date, "mmddyy")
  10. Set db = CurrentDb
  11. 'strSearchTable = "SELECT COUNT(*) FROM MSYSObjects WHERE (((MSYSObjects.Name)='tbl_LINK_PEJ'));"
  12.  
  13. If TableExists("" & strTableToFind & "") Then
  14.     CurrentDb.TableDefs.Delete ("" & strTableToFind & "")
  15. End If
  16.  
  17. Set tdfLinked = db.CreateTableDef("" & strTableToFind & "")
  18. tdfLinked.Connect = _
  19.     "Excel 5.0;HDR=YES;IMEX=2;DATABASE=" & myPath & myFile & ".xls"
  20. Debug.Print myPath & myFile & ".xls"
  21. tdfLinked.SourceTableName = "PEJ$"
  22. db.TableDefs.Append tdfLinked
  23. DoCmd.RunSQL "SELECT " & strTableToFind & ".ETFSymbol, " & strTableToFind & ".CUSIP, " & strTableToFind & ".ETFName, " & strTableToFind & ".TotalQty, " & strTableToFind & ".LastPrice INTO " & Me!comboChooseETF & "_" & TempDate & _
  24.                             " FROM " & strTableToFind
  25.  
  26. '    DoCmd.RunSQL "DELETE * FROM tbl_LINK_" & Me!comboChooseETF & ";"
  27. db.Close
  28. Set db = Nothing
  29. Set tdfLinked = Nothing
Apr 17 '07 #2
Corster
36
Hey, I've never tried any of this and I don't mean to patronise, but I would question the following:

strTableToFind = "tbl_LINK_" & Me!comboChooseETF
Could be that the item in the combo box is incorrect?

tdfLinked.SourceTableName = "PEJ$"
You said it could not find "PEJ$", try removing the "$" and including your file path and file extension:

Expand|Select|Wrap|Line Numbers
  1. tdfLinked.SourceTableName = myPath & Me!comboChooseETF.Text & ".xls"
But then again, I'm no expert... If this gets you anywhere though, let me know!
Apr 17 '07 #3
No luck with these suggestions unfortunately...I will be grateful to anyone who can help me with the connecting and linking from Access 2003 to Excel 2003.
Thank you.
Apr 17 '07 #4

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

Similar topics

1
by: c duden | last post by:
Excel won't allow documents to be linked to a worksheet in office 2000 when using C# to create an add-in. The following code snippets are what was used in the attempts (there are more...
4
by: Mark T. | last post by:
Hi, I've got a simple DB (Office Win XP Professional). Basically, it's like a check book register - deposit, deduction and running sum. I'd like to somehow link it to an Excel spreadsheet that...
6
by: oyk | last post by:
I hope someone could help me on this. I have linked an excel worksheet to access but the some data shown in the access table has the #Num errors. Presumably, this must be because the data in the...
6
by: jalmar | last post by:
Hello again: My second question is: I am linking an excel spreadsheet into Access, I have it linked and at first had problems getting the information imported into Access-it wasn't importing-I...
0
by: Sajit | last post by:
I am trying to use an Excel file as a template for an Access report. I Linked the Excel file through an unbound frame as an OLE object with the properties set as follows: Source Doc...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
1
by: afr0ninja | last post by:
Hello! I'm having an issue with the OutputTo function of Access. I have a few queries that I export to excel (by way of the OutputTo function) This works fine. I then take an excel sheet...
1
by: karthik28 | last post by:
I tried linking an excel spreadsheet to an access database. It shows me a window with the data but the header row in missing. However, when I open the excel file, save it without making any changes...
1
by: agarwasa2008 | last post by:
Hi, I have a perfect file called "Products.xls" that I link to my MS Access 2003 database and everytthing looks good in that file. When I view the same file after linking in my database the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.