H
Hal2604 via AccessMonster.com
I have a report in access where I am extracting some data out of excel to
generate the report. The code runs with out error, but comes out blank. On
the report the controls are lbl20-lbl27, & txt20-txt27. All of them are
labels. In the past I haven't been able to write excel to a text box. Below
is my code:
ClosingCount = 20
CenterCount = 40
CellNum = 3
PercentVAR = 5#
Set XLAPP = GetObject("Excel.Application") 'checks to see if an instance
of excel is running
If Err.Number <> 0 Then ' excel was not running
Set XLAPP = CreateObject("excel.application") ' creates an instance of
excel
End If
XLAPP.Visible = True
XLAPP.displayalerts = False
XLAPP.UserName = "PostCloseAnalyst1"
'Opens workbook
SysCmd acSysCmdSetStatus, "Opening Excel"
XLAPP.Workbooks.Open filename:="G:\Users\Post Close\clserr\NewPostClosing\
TotalErrors.xls"
Do While ClosingCount <= 27 And PercentVAR > 4.49 / 100
XLAPP.Windows("TotalErrors.xls").Activate
XLAPP.sheets("Summary").Select
XLAPP.Range("B" & CellNum).Select
PercentVAR = XLAPP.activecell
If XLAPP.activecell >= 4.49 / 100 Then
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=-1).Activate
Call CheckCenter(XLAPP.activecell) 'NJM 12/10
If bCenter = False Then 'closing errors
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=1).Activate
Report!memorandumNJM.Activate
tempT = "txt" & ClosingCount
memorandumNJM.Controls(tempT).Caption = XLAPP.activecell
XLAPP.Workbooks("TotalErrors.xls").Activate
XLAPP.Windows("TotalErrors.xls").Activate
XLAPP.strCellLoc = XLAPP.activecell
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=-1).Activate
Report!memorandumNJM.Activate
tempL = "lbl" & ClosingCount
memorandumNJM.Controls(tempL).Caption = XLAPP.activecell
memorandumNJM.Controls(tempT).Caption = Format(memorandumNJM.
Controls(tempT).Caption, "#0%")
ClosingCount = ClosingCount + 1
End If
End If
CellNum = CellNum + 1
Loop
Any help is appreciated.
Holly
generate the report. The code runs with out error, but comes out blank. On
the report the controls are lbl20-lbl27, & txt20-txt27. All of them are
labels. In the past I haven't been able to write excel to a text box. Below
is my code:
ClosingCount = 20
CenterCount = 40
CellNum = 3
PercentVAR = 5#
Set XLAPP = GetObject("Excel.Application") 'checks to see if an instance
of excel is running
If Err.Number <> 0 Then ' excel was not running
Set XLAPP = CreateObject("excel.application") ' creates an instance of
excel
End If
XLAPP.Visible = True
XLAPP.displayalerts = False
XLAPP.UserName = "PostCloseAnalyst1"
'Opens workbook
SysCmd acSysCmdSetStatus, "Opening Excel"
XLAPP.Workbooks.Open filename:="G:\Users\Post Close\clserr\NewPostClosing\
TotalErrors.xls"
Do While ClosingCount <= 27 And PercentVAR > 4.49 / 100
XLAPP.Windows("TotalErrors.xls").Activate
XLAPP.sheets("Summary").Select
XLAPP.Range("B" & CellNum).Select
PercentVAR = XLAPP.activecell
If XLAPP.activecell >= 4.49 / 100 Then
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=-1).Activate
Call CheckCenter(XLAPP.activecell) 'NJM 12/10
If bCenter = False Then 'closing errors
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=1).Activate
Report!memorandumNJM.Activate
tempT = "txt" & ClosingCount
memorandumNJM.Controls(tempT).Caption = XLAPP.activecell
XLAPP.Workbooks("TotalErrors.xls").Activate
XLAPP.Windows("TotalErrors.xls").Activate
XLAPP.strCellLoc = XLAPP.activecell
XLAPP.activecell.Offset(rowOffset:=0, columnOffset:=-1).Activate
Report!memorandumNJM.Activate
tempL = "lbl" & ClosingCount
memorandumNJM.Controls(tempL).Caption = XLAPP.activecell
memorandumNJM.Controls(tempT).Caption = Format(memorandumNJM.
Controls(tempT).Caption, "#0%")
ClosingCount = ClosingCount + 1
End If
End If
CellNum = CellNum + 1
Loop
Any help is appreciated.
Holly