Problem: If Then Else.... help!

NRGZ

New member
Local time
Today, 03:54
Joined
Aug 9, 2021
Messages
15
no matter how a dice this i cant get it right it just keeps saying 'else wihout if'...... any help appreciated!
Private Sub VAT()

Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single

a = Me.Sales_Price
b = Me.VAT_Percentage
d = Me.Qty

If IsNull(Me.VAT_Percentage) Then End

Else: Me.VAT_Amount = (b / 100 * a) * d
' Me.VAT_Amount = c
End If


End Sub

Many Thanks,
 
Your construct is not correct, try this instead
Code:
If Not IsNull(Me.Vat_percentage) Then

    Me.VAT_Amount = (b / 100 * a) * d

End If
 
Your construct is not correct, try this instead
Code:
If Not IsNull(Me.Vat_percentage) Then

    Me.VAT_Amount = (b / 100 * a) * d

End If
It now says 'invalid use of NULL' with b = Me.VAT_Percentage (has the yellow arrow pointing at it)
locals say that it is '0' so i'm not sure.
 
And just so you know, the syntax for if\else is either single line:

If A then B else C

Or multiline:

If A then
B
Else
C
End if


If you can jam into 1 line then no End if
 
Before you assign the values to your variables, check for values, something like

If IsNull(Me.Vat_percentage) Then Exit Sub

Then you can do without the other test, as it won't be null if it reaches it.
 
I tried that but it didnt work. had another look and this seems to work, more testing to be done but looks good,
Private Sub VAT()

Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single

If Me.VAT_Code = "0" Then Exit Sub

' If IsNull(Me.VAT_Code) Then Exit Sub

a = Me.Sales_Price
b = Me.VAT_Percentage
d = Me.Qty



' If Me.VAT_Code = "0" Then End

Me.VAT_Amount = (b / 100 * a) * d


'If Not IsNull(Me.VAT_Percentage) Then

' Me.VAT_Amount = (b / 100 * a) * d

'End If

End Sub

(i've included all me 'workings' but i'll clear it our for final code.)
Thanks All.
 
That's really confusing.
You are checking for a string by using "0", not a number.
Is that your intention?

To check for the number 0 you would use

If Me.VAT_Code = 0 Then Exit Sub
 
That's really confusing.
You are checking for a string by using "0", not a number.
Is that your intention?

To check for the number 0 you would use

If Me.VAT_Code = 0 Then Exit Sub
ahhh see always learning something, no i was trying to check for he value 0 so i've changed it accordingly.
Lets see how it goes.
Thanks.
 
Dim a As Double
Dim b As Double
Dim c As Double
Dim d As Doule

a = Nz(Me.Sales_Price,0)
b = Nz(Me.VAT_Percentage,0)
d = Nz(Me.Qty,0)

If a = 0 Or b = 0 Then
Exit Sub

Else
Me.VAT_Amount = (b / 100 * a) * d
' Me.VAT_Amount = c
End If
 

Users who are viewing this thread

Back
Top Bottom