Link to home
Start Free TrialLog in
Avatar of Cdhirst
Cdhirst

asked on

I need to export data from an access query into and premade excel document. i want the access data to specific cells in the excel doument.

I have a query which creates a form depending on what number I type in. I have created a button to export the data to excel. when I click this button I want it to export and fill the data into specific excel boxes of a premade excel document. how can I do this?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

that will all depend on the format of the "premade Excel document"

see the sample codes from Using Automation to Transfer Data to Microsoft Excel
Avatar of Cdhirst
Cdhirst

ASKER

i can show you the excel document if that would help ??
Avatar of Cdhirst

ASKER

The excel doc look like this.. My query creates a report that looks the same as this but i cant to convert the report/query into this excel doc
Avatar of Cdhirst

ASKER

here is the doc
Premade-excel.xlsx
what is the record source of the report?
copy and paste here.
Avatar of Cdhirst

ASKER

I think this is what you need?

L:\My Documents\Premade excel.xlsx
Avatar of Cdhirst

ASKER

sorry I miss read
the record source from the report if found from running a query to find a specific record in a table
try these codes for a starter, continue the codes where i placed 'etc..


sub CopyToExcel()
dim xlObj as object, rs as DAO.recordset

set rs=currentdb.openrecordset("NameOfQuery")
if rs.eof then exit sub

set xlObj=createobject("excel.application")
      xlObj.workbooks.open "L:\My Documents\Premade excel.xlsx"
      with xlObj
           .worksheets("sheet1").select
           .range("b2").value=rs!partnumber
           .range("e2").value=rs!Rev
           .range("b6").value=rs!partnumber

         '.. etc....

         .activeworkbook.save  
      end with
          xlObj.quit
end sub
Avatar of Cdhirst

ASKER

Here is the access database I have made
when u go to the switchboard click on 'ncm report' that will then open a box type in number 7605
this will then open a report. on the report I need a button that will send this report to excel in the format of the above excel document.
with the part number matching part number on the excel document and so on...
NCM-Data.accdb
Avatar of Cdhirst

ASKER

I will try you code now quickly
Avatar of Cdhirst

ASKER

I couldn't get it to work I am not very experienced with VBA
post here, which field from the query goes to which cell in the excel file.



.
Avatar of Cdhirst

ASKER

ID from the query goes to NCM number
what about the other fields????
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cdhirst

ASKER

Part number goes to part number
Supplier goes to company..
I can probably work out how to get the rest in if I have a few code lines in..
I have left my computer for today and won't be back till Thursday.. Can't really match them up till I am back.
Is it possible to contact again on Thursday?
Avatar of Cdhirst

ASKER

Thank I will check it out ASAP
Avatar of Cdhirst

ASKER

Thank you very much that worked really well
Avatar of Cdhirst

ASKER

Works really well thank you. Might have a few more problems but I will raise another question if I do
Avatar of Cdhirst

ASKER

HI
I have one more question about it. the company box in my report shows as text but when in exports to excel it shows up as a number. do you know how to change this as when it goes to excel I want it to show the company name not a number. when I tried it with your version it worked fine. cant understand why mine isn't
did you look at the sample db i uploaded?
Avatar of Cdhirst

ASKER

yes I did I managed to solve it thank you.

I was woundering if you knew how to get access to close itself automatically after a period of inactivity?