B
Bill
Hi,
The code is in a module. Using access 2000. Module is
called up from a command button on the form (called
calculate). Calls up the Fuction "tube Select" of which
Sub Price_2way() ' pricing subroutine common
is called up.
I took out the common subroutine in a function which is
called up in a "Case Select" .
At the start I open an Excel worksheet,
With xlapp
.Visible = False
Set xlbook = .Workbooks.Open("C:\My
Documents\2WAYPRICES.xls")
Set xlsheet = xlbook.Worksheets(2)
xlbook.Worksheets(2).Activate
End With
The Case select is based on a control value on an Acces
form - like,
Select Case Forms![tubeselectform]!Frame110 ' tube size
Me![tube size].
' each number in Case IS - represents a
diameter of pipe in millimetres.
Case Is = 50
Set rng1 = xlsheet.Range("b4:b75")
xlsheet.Range("b4").Activate
Call Price_2way
Case Is = 65
Set rng2 = xlsheet.Range("c4:c75")
xlsheet.Range("c4").Activate
Call Price_2way
Price two way is common so I extracted it out to give,
Sub Price_2way() ' pricing subroutine common
Dim rng11 As Range
Dim rng21 As Range
Dim rng31 As Range
Dim rng41 As Range
Dim c As Integer
Dim res As Variant
Dim res2 As Variant
Dim res3 As Variant
'look at the material option
If (Forms![tubeselectform]![Grade] = 1)
Then 'non sanitary mild steel
c = -3
ElseIf (Forms![tubeselectform]!
[Grade] = 2) Then ' non sanitary 304
c = -4
ElseIf (Forms![tubeselectform]!
[Grade] = 3) Then '316 stst option.
c = -8
Else
'do nothing
End If
Set rng11 = ActiveCell.Offset(c,
0).Value
res = ""
res = rng11
'rng11 is the value to be copied to
field Forms![tubeselectform]![Price_Tube_Size)
Forms![tubeselectform]!
[Price_Tube_Size] = res
'now look at the Cover option
If (Forms![tubeselectform]![Cover] = 2)
Then 'cover is 304 ss
c = -30
ElseIf (Forms![tubeselectform]!
[Cover] = 3) Then ' cover is 316 ss
c = -31
Else
c = -1
End If
Set rng21 = xlsheet.ActiveCell.Offset
(c, 0).Value
res2 = ""
res2 = rng21
'rng21 is the value to be copied to
field Forms![tubeselectform]![Price_Cover_Option]and will
be numeric.
Forms![tubeselectform]!
[Price_Cover_Option] = res2
'now look at the Controller option
If (Forms![tubeselectform]![DC] = True)
Then
c = -29
ElseIf (Forms![tubeselectform]![DC] =
False) Then
c = -28
Else
'do nothing
End If
Set rng31 = xlsheet.ActiveCell.Offset
(c, 0).Value
res3 = ""
res3 = rng31
'rng31 is the value to be copied to
field Forms![tubeselectform]![Price_Prologic)
Forms![tubeselectform]!
[Price_Prologic] = res3
End Sub
When it runs I get an error at the line,
Set rng11 = ActiveCell.Offset(c, 0).Value
saying "Object variable or With Block Variable not set.
In the "case Is" I activate the active cell. In the sub
routine I offset to get a value - or do I?????.
Where have I gone wrong????.
Thanks In advance
Bill
The code is in a module. Using access 2000. Module is
called up from a command button on the form (called
calculate). Calls up the Fuction "tube Select" of which
Sub Price_2way() ' pricing subroutine common
is called up.
I took out the common subroutine in a function which is
called up in a "Case Select" .
At the start I open an Excel worksheet,
With xlapp
.Visible = False
Set xlbook = .Workbooks.Open("C:\My
Documents\2WAYPRICES.xls")
Set xlsheet = xlbook.Worksheets(2)
xlbook.Worksheets(2).Activate
End With
The Case select is based on a control value on an Acces
form - like,
Select Case Forms![tubeselectform]!Frame110 ' tube size
Me![tube size].
' each number in Case IS - represents a
diameter of pipe in millimetres.
Case Is = 50
Set rng1 = xlsheet.Range("b4:b75")
xlsheet.Range("b4").Activate
Call Price_2way
Case Is = 65
Set rng2 = xlsheet.Range("c4:c75")
xlsheet.Range("c4").Activate
Call Price_2way
Price two way is common so I extracted it out to give,
Sub Price_2way() ' pricing subroutine common
Dim rng11 As Range
Dim rng21 As Range
Dim rng31 As Range
Dim rng41 As Range
Dim c As Integer
Dim res As Variant
Dim res2 As Variant
Dim res3 As Variant
'look at the material option
If (Forms![tubeselectform]![Grade] = 1)
Then 'non sanitary mild steel
c = -3
ElseIf (Forms![tubeselectform]!
[Grade] = 2) Then ' non sanitary 304
c = -4
ElseIf (Forms![tubeselectform]!
[Grade] = 3) Then '316 stst option.
c = -8
Else
'do nothing
End If
Set rng11 = ActiveCell.Offset(c,
0).Value
res = ""
res = rng11
'rng11 is the value to be copied to
field Forms![tubeselectform]![Price_Tube_Size)
Forms![tubeselectform]!
[Price_Tube_Size] = res
'now look at the Cover option
If (Forms![tubeselectform]![Cover] = 2)
Then 'cover is 304 ss
c = -30
ElseIf (Forms![tubeselectform]!
[Cover] = 3) Then ' cover is 316 ss
c = -31
Else
c = -1
End If
Set rng21 = xlsheet.ActiveCell.Offset
(c, 0).Value
res2 = ""
res2 = rng21
'rng21 is the value to be copied to
field Forms![tubeselectform]![Price_Cover_Option]and will
be numeric.
Forms![tubeselectform]!
[Price_Cover_Option] = res2
'now look at the Controller option
If (Forms![tubeselectform]![DC] = True)
Then
c = -29
ElseIf (Forms![tubeselectform]![DC] =
False) Then
c = -28
Else
'do nothing
End If
Set rng31 = xlsheet.ActiveCell.Offset
(c, 0).Value
res3 = ""
res3 = rng31
'rng31 is the value to be copied to
field Forms![tubeselectform]![Price_Prologic)
Forms![tubeselectform]!
[Price_Prologic] = res3
End Sub
When it runs I get an error at the line,
Set rng11 = ActiveCell.Offset(c, 0).Value
saying "Object variable or With Block Variable not set.
In the "case Is" I activate the active cell. In the sub
routine I offset to get a value - or do I?????.
Where have I gone wrong????.
Thanks In advance
Bill