[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need a worksheet/spreadsheet to be created with each new record

Posted on 2011-09-09
9
Medium Priority
?
336 Views
Last Modified: 2012-05-12
I currently have a database I am working on and I need to have a spreadsheet or something similar attached to each record. I need the spreadsheet to be created when the record is created. Any ideas how I can do this or something similar?
0
Comment
Question by:timamartin
[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
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 36512193
Which version of Access?
0
 
LVL 35

Expert Comment

by:Norie
ID: 36512223
How wil the records be created?

Is it via a form?

The following will create a new, single sheet Excel workbook in the same directory of the database with the name taken from Field1 on the form.
Option Compare Database
Option Explicit

Const xlWBATWorksheet = -4167


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim xlApp As Object
Dim xlWB As Object
Dim strName As String
Dim strPath As String


    If Me.NewRecord Then
    
        strPath = CurrentProject.Path
        strName = Me.Field1
        Set xlApp = CreateObject("Excel.Application")
        
       Set xlWB = xlApp.Workbooks.Add(xlWBATWorksheet)
        
        xlWB.SaveAs strPath & "/" & strName
        
        xlWB.Close
        
        xlApp.Quit
        
        Set xlWB = Nothing
        Set xlApp = Nothing
        
    End If
    

End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36512246
<have a spreadsheet or something similar attached to each record.>
"Or something similar"?
What exactly are you asking for? what would "Something Similar" be?


<I need the spreadsheet to be created when the record is created.>
And what is in this spreadsheet?

Creating a new File for each record seems a bit extreme...

Can you perhaps First take a moment and explain the need for this...
What is your ultimate goal here?

Perhaps there is a simpler approach...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:Norie
ID: 36512280
Even though I posted code, I've got to agree here - creating something for each record seems a bit much.

I could maybe understand a new worksheet in an existing workbook but even that's a bit much.
0
 

Author Comment

by:timamartin
ID: 36512323
I am currently using version 2010.
0
 

Author Comment

by:timamartin
ID: 36512334
The database is to track all of the company's departmental projects. Along with the pertinent info like what the project is, why dates and costs there is a button that will open up a WorkPlan for the project. The workplan could be an Excel spreadsheet that I already have. I suppose this would be ideal because I could set it up as a template.
0
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 36512394
The code I posted will create a new workbook and can be adapted to add a worksheet to an existing workbook or create the workbooks from a template.
Option Compare Database
Option Explicit
Const xlWBATWorksheet = -4167

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim strName As String
Dim strPath As String

    If Me.NewRecord Then
    
        strPath = "C:\" ' path to workbplan spreadsheet

        strName = Me.Field1

        Set xlApp = CreateObject("Excel.Application")
        
       Set xlWB = xlApp.Workbooks.Open(strPath & "\Workplan.xlsx")
        
       Set xlWS = xlWB.Worksheets.Add
 
       xlWS.Name = strName


        xlWB.Close True
        
        xlApp.Quit
        
        Set xlWB = Nothing
        Set xlApp = Nothing
        
    End If
    

End Sub

Open in new window

0
 

Author Comment

by:timamartin
ID: 36512504
When you attach a document to a record via a form does it just link to the doc or does it somehow embed it?
0
 
LVL 35

Expert Comment

by:Norie
ID: 36512749
Could you please clarify what you want to do?
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

650 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