exporting a record from access to excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashitaka65
    New Member
    • Jul 2007
    • 24

    #31
    so there is no way to have it default to a certain cell then from there append to empty cells?

    i have it exporting to a form that i must use and it has info on the top of the page then the body is empty then a place for signatur and date at the bottom of the page, i need to have it start at the 16th cell if not it starts at the end of the page after all the blank body and after the signature

    Comment

    • FishVal
      Recognized Expert Specialist
      • Jun 2007
      • 2656

      #32
      Try this.

      [code=vb]
      Private Sub btnXL_Click()

      Dim appExcel As Excel.Applicati on
      Dim wkbWorkBook As Excel.Workbook
      Dim wksSheet As Excel.Worksheet
      Dim rngOutputTo As Excel.Range

      ' creates Excel application
      Set appExcel = CreateObject("E xcel.Applicatio n")
      ' opens workbook for output (C:\target.xls)
      Set wkbWorkBook = appExcel.Workbo oks.Open("c:\ta rget.xls")
      ' get reference to sheet for output (Sheet1)
      Set wksSheet = wkbWorkBook.Wor ksheets("Sheet1 ")

      Set rngOutputTo = GetOutputToRang e(wksSheet)
      If rngOutputTo Is Nothing Then
      MsgBox "No rows available in output file"
      GoTo Quit
      End If

      ' output all fields in the record
      For Each fld In Me.Recordset.Fi elds
      rngOutputTo.Val ue = fld.Value
      Set rngOutputTo = rngOutputTo.Off set(ColumnOffse t:=1)
      Next

      ' save and quit
      wkbWorkBook.Sav e
      Quit:
      appExcel.Quit

      Set rngOutputTo = Nothing
      Set wksSheet = Nothing
      Set wkbWorkBook = Nothing
      Set appExcel = Nothing

      End Sub

      Private Function GetOutputToRang e(ByRef wksSheet As Excel.Worksheet ) As Excel.Range

      Dim rngcell As Excel.Range

      ' get A-cell in the first empty row of the range defined in output XLS file
      ' output range starts from column A and limited by rows 16-30
      For Each rngcell In wksSheet.Range( "A16:A20")
      For i = 0 To Me.Recordset.Fi elds.Count - 1
      If rngcell.Offset( 0, i).Value = "" Then
      Set GetOutputToRang e = rngcell.Offset( 0, i)
      Exit Function
      End If
      Next i
      Next

      End Function
      [/code]

      Comment

      Working...