?
Solved

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

Posted on 2011-09-09
9
Medium Priority
?
341 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

862 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