Insert Access Dbase Field into a specific cell

K

K

Good day,

I have a field called HeaderOne on an Access Dbase and I would like to open
an excel workbook and insert the information into a sepecific cell say for
example A1. How would I code this? Any help is appreciated.

Thank you, for your time. Kyle.
 
M

mcescher

Good day,

I have a field called HeaderOne on an Access Dbase and I would like to open
an excel workbook and insert the information into a sepecific cell say for
example A1. How would I code this? Any help is appreciated.

Thank you, for your time. Kyle.

Make sure you add Excel to the list of references. Tools ->
References. Then, try this code...

Public Sub WriteToExcel()
Dim xlaReport As Excel.Application
Dim xlbReport As Excel.Workbook
Dim xlsReport As Excel.Worksheet
Dim strQuery As String
Dim db As Database
Dim rs As Recordset
strQuery = "SELECT HeaderOne FROM YourQuery; "
Set db = CurrentDb()
Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)
xlsReport.Range("A1").CopyFromRecordset rs
Set rs = Nothing
Set db = Nothing
End Sub

Hope this helps,
Chris M.
 
M

mcescher

Make sure you add Excel to the references.  Tools -> References.
 Then, try this code...

Public Sub WriteToExcel()
  Dim xlaReport As Excel.Application
  Dim xlbReport As Excel.Workbook
  Dim xlsReport As Excel.Worksheet
  Dim strQuery As String
  Dim db As Database
  Dim rs As Recordset
Excel.Application.Visible = True
Set xlaReport = Excel.Application
Set xlbReport = xlaReport.Workbooks.Open(strFullPth)

  strQuery = "SELECT HeaderOne FROM YourQuery; "
  Set db = CurrentDb()
  Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)
  xlsReport.Range("A1").CopyFromRecordset rs
  Set rs = Nothing
  Set db = Nothing
End Sub

Hope this helps,
Chris M.
 
M

mcescher

Make sure you add Excel to the references.  Tools -> References.
 Then, try this code...

Public Sub WriteToExcel()
   Dim xlaReport As Excel.Application
   Dim xlbReport As Excel.Workbook
   Dim xlsReport As Excel.Worksheet
   Dim strQuery As String
   Dim db As Database
   Dim rs As Recordset
   Excel.Application.Visible = True
   Set xlaReport = Excel.Application
   Set xlbReport = xlaReport.Workbooks.Open(strFullPth)

   strQuery = "SELECT HeaderOne FROM YourQuery; "
   Set db = CurrentDb()
   Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)
   xlsReport.Range("A1").CopyFromRecordset rs
   Set rs = Nothing
   Set db = Nothing
End Sub

Hope this helps,
Chris M.

Oops, forgot about strFullPath, Dim it as a string, and put the entire
path to your spreadsheet in there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top