I am developing an Access application in Access 2003 using Access as the front end and SQL Server as the back end database. The following subroutine titled StartDocLN works fine in my application.
Do you know how I could modify the SECOND subroutine that follows named Calc_subtotals
to use objects similar to those used in StartDocLN ?
I have encountered errors compiling Calc_subtotals.
For ex: the compiler states that Method or data member not found for
Application.ScreenUpdating
= False <--- Compiler highlights Screenupdating
--------------------------
----------
----------
----------
----------
----------
----------
----------
--
Private Sub StartDocLN(filename)
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Open(filen
ame)
Set xlWS = xlWB.Worksheets(1)
xlWS.Columns.AutoFit
xlApp.ScreenUpdating = True
End Sub
--------------------------
----------
----------
----------
----------
----------
------
Private Sub Calc_subtotals(filename)
Dim str As String
Dim lastrow As Long
Dim i As Long
Dim rng As Range
Dim celle As Range
Dim str1 As String
Dim str2 As String
Dim rowe As Long
Dim temp As Double
Application.ScreenUpdating
= False
rowe = 2
str1 = "A"
str2 = "E"
With Sheets("Sheet1")
Set rng = Range(.Cells(rowe, str1), .Cells(.Cells.Rows.count, str2).End(xlUp))
End With
rng.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Key3:=Range("E2"), Order3:=xlAscending, Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
, _
DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal,
DataOption3:= _
xlSortNormal
str = "B"
With Sheets("Sheet1")
lastrow = .Cells(.Cells.Rows.count, str).End(xlUp).Offset(1, 0).Row
For i = lastrow To 3 Step -1
If .Cells(i, "B") <> .Cells(i - 1, "B") Then
.Rows(i).Insert Shift:=xlDown
End If
Next i
str = "B"
lastrow = .Cells(.Cells.Rows.count, str).End(xlUp).Offset(1, 0).Row
temp = 0
For i = 2 To lastrow
temp = temp + Cells(i, 5)
If Cells(i, 5) = "" Then
Cells(i, 6) = temp
temp = 0
Cells(i, 1) = "Sub-total"
End If
Next i
End With
Columns("F:F").NumberForma
t = "#,##0.00"
Application.ScreenUpdating
= True
End Sub
Start Free Trial