PDA

View Full Version : help with transfering data from access to excel



casual-rich
03-16-2009, 02:44 AM
hi im doing a project at uni and i have got to transfer date from access to excel do a calcualtion on a number of things in excel and then transfer the data back into access,

here is the code that i have done so far
Private Sub Transfer_To_Excel_Click()
Dim oApp As Object
Set oApp = CreateObject(Class:="Excel.Application")
oApp.Workbooks.Open "F:\Richard's Uni Sept 08-09\BSADC\assignment 3\samedayInvoice.xls"
oApp.Visible = True
oApp.Sheets("invoice").[E9].Value = Distance.Value



Set oApp = CreateObject(Class:="Excel.Application")
oApp.Workbooks.Open "F:\Richard's Uni Sept 08-09\BSADC\assignment 3\samedayInvoice.xls"
oApp.Visible = True
oApp.Sheets("invoice").[B9].Value = DeliveryNo.Value
End Sub

it transfers the data brill but jsut one problem it will open two excel documents what am I doing wrong please help me guys

any help will be brill

rich

CreganTur
03-16-2009, 05:12 AM
Welcome to the forum- it's always good to see new members.

I'm guessing that uni means University? Thanks for letting us know it's a homework problem. There is nothing wrong with asking for help with homework, we just need to know so we provide appropriate help.

Your code is opening two Excel Spreadsheets because you are instantiating and opening two Excel objects. You only need to create an object once in order to use it; you can interact with any/multiple ranges in the worksheet after you instantiate it a single time.

Take a look at your code and see if this helps you figure out what's going on.