Access.2007.VBA.Bibl..

(John Hannent) #1

Write Access data from a record directly to cells in the worksheet:


rngStart.Activate
rngStart.Value = Nz(![ContactID])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=1)
rng.Value = Nz(![CompanyName])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=2)
rng.Value = Nz(![FirstName])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=3)
rng.Value = Nz(![LastName])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=4)
rng.Value = Nz(![Salutation])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=5)
rng.Value = Nz(![StreetAddress])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=6)
rng.Value = Nz(![City])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=7)
rng.Value = Nz(![StateOrProvince])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=8)
rng.Value = Nz(![PostalCode])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=9)
rng.Value = Nz(![Country])
Set rng = _
appExcel.ActiveCell.Offset(columnoffset:=10)
rng.Value = Nz(![JobTitle])

Go to the first column of the next row:


rngStart.Activate
Set rngStart = _
appExcel.ActiveCell.Offset(rowoffset:=1)
.MoveNext
Loop
End With

MsgBox β€œAll Contacts exported!”

Working with Excel Worksheets 7

Free download pdf