PDA

View Full Version : Send information from Access to Excel



juanpauk
01-14-2007, 06:17 AM
Hello,

I am new here and I would like to ask how can I copy information from a text box in a form and paste it to an specific cell in excel. I have been able to open the specific excel file from access but i am stuck now.
Thank You

Juan Pablo

OBP
01-14-2007, 09:54 AM
Hello juanpauk.
There are 2 ways to do this, it can be done in VBA or it can be done from a form using the DDESend Function.
Can I ask why you are sending the data to Excel, rather that using Access?

OBP
01-14-2007, 10:15 AM
If you want to use the VBA method then I just did it with this, where the Excel workbook is Book1, it uses sheet1 and range a12 and the text box on the form is text0
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

Dim excelName As String
Dim AppExcel As New Excel.Application
Dim Wkb As Workbook
Dim Wksh As Worksheet
Dim cellArray As Variant, count As Integer, counter As Integer, excelTitles As String
Dim xlRng As Range


'assigned path and file name
excelName = "c:\Access\Book1"

Set Wkb = AppExcel.Workbooks.Open(excelName)
Set Wksh = Wkb.Sheets(1)
Wksh.Range("a12") = Me.Text0

Wkb.Close
AppExcel.Quit
Set Wkb = Nothing
Set AppExcel = Nothing

Beep

Exit Sub

Errorcatch:
MsgBox Err.Description
If IsNull(Wkb) = False Then Exit Sub
Wkb.Close
AppExcel.Quit
Set Wkb = Nothing
Set AppExcel = Nothing

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub


There may be better ways but it does work for me.

juanpauk
01-14-2007, 10:32 AM
Hello OBP!

Many thanks for your prompt response. The reason why I am doing this is because I am trying to complete an assignment for university and one of the requirements is that i know how to send information from access to excel.

What I am trying to do at the moment is that having captured the order details from a customer in access, that i can then send all those details to a spreadsheet template that will print the delivery label. (I don't know if it makes sense)

I will try your example and will let you know if it works. Many thanks again.

JP