Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access VBA syntax to include Access Table fields

Posted on 2013-05-14
3
Medium Priority
?
429 Views
Last Modified: 2013-05-15
Hello Experts,

Please provide assistance to include a MS Access table field that displays the Path and the File Name as I am receiving a Run Time Error 1004 that displays "Could not be found".  I first tried the Spreadsheet Name without the http:// prefix then I tried what is below.
ID      SpreadsheetName                                                                SpreadsheetTab
1      http://X:\2013 reports\cfi consol nod 0313.xlsm                           Output 1
2      http://X:\2013 reports\cfmi consol 0313.xlsm                               Output 1
3      http://X:\Reports Close\CFMI Pre_Close_w_filters_RiskNEW.xlsm  Output 1 (100.100.T05)

and the VBA:
Private Sub WorksheetsCopy_Click()
Dim CopyFrom As Object
Dim CopyTo As Object
Dim CopyThis As Object
Dim xl As Object
Dim SpreadsheetName As String
Dim SpreadsheetTab As String
Dim ID As Field
Dim rs As Recordset
Dim oldPath As String, newPath As String
''Late binding
Set xl = CreateObject("Excel.Application")
xl.Visible = True
newPath = "H:\PDF"
Set rs = CurrentDb.OpenRecordset("TblReports")

Do While Not (rs.EOF)
''To use a password: Workbooks.Open Filename:="Filename", Password:="Password"
Set CopyFrom = xl.Workbooks.Open([SpreadsheetName])
Set CopyThis = CopyFrom.Sheets([SpreadsheetTab]) ''Sheet number 1
Set CopyTo = xl.Workbooks.Open("H:\PDF\MasterCopy.xlsx")
CopyThis.Copy After:=CopyTo.Sheets(CopyTo.Sheets.Count)
    rs.MoveNext
   CopyFrom.Close False

Loop

rs.Close

End Sub


Thanks,
Bob
0
Comment
Question by:CFMI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 39164351
Where do you get this error?

In order to refer to a Field in your Recordset you use syntax like this:

rs("YourFieldName")

There are other variations to this also:

rs![YourFieldName]

Either is fine.
0
 
LVL 1

Author Comment

by:CFMI
ID: 39164406
Great, the field is recogized but now I receive a type mismatch on the second statement, "Set CopyThis = CopyFrom.Sheets(rs("SpreadsheetTab"))"
0
 
LVL 1

Author Closing Comment

by:CFMI
ID: 39167877
The field syntax worked well.
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question