J
John Ortt
Are there any techniques I can use to simplify (and or shorten) the
following code please?
It all works but it is rather ungainly.
Thanks in Advance,
John
Code Follows:
//////////////////////////////////
Sub PRICE()
Dim MeMOQ As Integer, MePB2 As Integer, MePB3 As Integer, MePB4 As Integer,
MePB5 As Integer, MePB6 As Integer, MePB7 As Integer, MePB8 As Integer,
MePB9 As Integer, MePB10 As Integer
Dim MePRICE1 As Double, MePRICE2 As Double, MePRICE3 As Double, MePRICE4 As
Double, MePRICE5 As Double, MePRICE6 As Double, MePRICE7 As Double, MePRICE8
As Double, MePRICE9 As Double, MePRICE10 As Double
MeMOQ = Nz(Me.MOQ)
MePB2 = Nz(Me.PB2)
MePB3 = Nz(Me.PB3)
MePB4 = Nz(Me.PB4)
MePB5 = Nz(Me.PB5)
MePB6 = Nz(Me.PB6)
MePB7 = Nz(Me.PB7)
MePB8 = Nz(Me.PB8)
MePB9 = Nz(Me.PB9)
MePB10 = Nz(Me.PB10)
MePRICE1 = Nz(Me.PRICE1)
MePRICE2 = Nz(Me.PRICE2)
MePRICE3 = Nz(Me.PRICE3)
MePRICE4 = Nz(Me.PRICE4)
MePRICE5 = Nz(Me.PRICE5)
MePRICE6 = Nz(Me.PRICE6)
MePRICE7 = Nz(Me.PRICE7)
MePRICE8 = Nz(Me.PRICE8)
MePRICE9 = Nz(Me.PRICE9)
MePRICE10 = Nz(Me.PRICE10)
Dim ErrorMess As String
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = True: Me.PRICE4.Enabled = True
If MeMOQ = Null Or MeMOQ < 1 Or MePRICE1 = Null Or MePRICE1 < 0.01 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = False:
Me.PRICE2.Enabled = False: Me.PB3.Enabled = False: Me.PRICE3.Enabled =
False: Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB2 = Null Or MePB2 <= MeMOQ Or MePRICE2 = Null Or MePRICE2 >=
MePRICE1 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = False: Me.PRICE3.Enabled = False:
Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB3 = Null Or MePB3 <= MePB2 Or MePRICE3 = Null Or MePRICE3 >=
MePRICE2 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB4 = Null Or MePB4 <= MePB3 Or MePRICE4 = Null Or MePRICE4 >=
MePRICE3 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = True: Me.PRICE4.Enabled = True
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
etc
End If
following code please?
It all works but it is rather ungainly.
Thanks in Advance,
John
Code Follows:
//////////////////////////////////
Sub PRICE()
Dim MeMOQ As Integer, MePB2 As Integer, MePB3 As Integer, MePB4 As Integer,
MePB5 As Integer, MePB6 As Integer, MePB7 As Integer, MePB8 As Integer,
MePB9 As Integer, MePB10 As Integer
Dim MePRICE1 As Double, MePRICE2 As Double, MePRICE3 As Double, MePRICE4 As
Double, MePRICE5 As Double, MePRICE6 As Double, MePRICE7 As Double, MePRICE8
As Double, MePRICE9 As Double, MePRICE10 As Double
MeMOQ = Nz(Me.MOQ)
MePB2 = Nz(Me.PB2)
MePB3 = Nz(Me.PB3)
MePB4 = Nz(Me.PB4)
MePB5 = Nz(Me.PB5)
MePB6 = Nz(Me.PB6)
MePB7 = Nz(Me.PB7)
MePB8 = Nz(Me.PB8)
MePB9 = Nz(Me.PB9)
MePB10 = Nz(Me.PB10)
MePRICE1 = Nz(Me.PRICE1)
MePRICE2 = Nz(Me.PRICE2)
MePRICE3 = Nz(Me.PRICE3)
MePRICE4 = Nz(Me.PRICE4)
MePRICE5 = Nz(Me.PRICE5)
MePRICE6 = Nz(Me.PRICE6)
MePRICE7 = Nz(Me.PRICE7)
MePRICE8 = Nz(Me.PRICE8)
MePRICE9 = Nz(Me.PRICE9)
MePRICE10 = Nz(Me.PRICE10)
Dim ErrorMess As String
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = True: Me.PRICE4.Enabled = True
If MeMOQ = Null Or MeMOQ < 1 Or MePRICE1 = Null Or MePRICE1 < 0.01 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = False:
Me.PRICE2.Enabled = False: Me.PB3.Enabled = False: Me.PRICE3.Enabled =
False: Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB2 = Null Or MePB2 <= MeMOQ Or MePRICE2 = Null Or MePRICE2 >=
MePRICE1 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = False: Me.PRICE3.Enabled = False:
Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB3 = Null Or MePB3 <= MePB2 Or MePRICE3 = Null Or MePRICE3 >=
MePRICE2 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = False: Me.PRICE4.Enabled = False
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
ElseIf MePB4 = Null Or MePB4 <= MePB3 Or MePRICE4 = Null Or MePRICE4 >=
MePRICE3 Then
Me.MOQ.Enabled = True: Me.PRICE1.Enabled = True: Me.PB2.Enabled = True:
Me.PRICE2.Enabled = True: Me.PB3.Enabled = True: Me.PRICE3.Enabled = True:
Me.PB4.Enabled = True: Me.PRICE4.Enabled = True
Me.PB5.Enabled = False: Me.PRICE5.Enabled = False: Me.PB6.Enabled = False:
Me.PRICE6.Enabled = False: Me.PB7.Enabled = False: Me.PRICE7.Enabled =
False: Me.PB8.Enabled = False: Me.PRICE8.Enabled = False
Me.PB9.Enabled = False: Me.PRICE9.Enabled = False: Me.PB10.Enabled = False:
Me.PRICE10.Enabled = False
etc
End If