Problem: If Then Else.... help! (1 Viewer)

NRGZ

New member
Local time
Today, 14:46
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,
 

Minty

AWF VIP
Local time
Today, 14:46
Joined
Jul 26, 2013
Messages
10,368
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
 

NRGZ

New member
Local time
Today, 14:46
Joined
Aug 9, 2021
Messages
15
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.
 

plog

Banishment Pending
Local time
Today, 08:46
Joined
May 11, 2011
Messages
11,638
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
 

Minty

AWF VIP
Local time
Today, 14:46
Joined
Jul 26, 2013
Messages
10,368
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.
 

NRGZ

New member
Local time
Today, 14:46
Joined
Aug 9, 2021
Messages
15
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.
 

Minty

AWF VIP
Local time
Today, 14:46
Joined
Jul 26, 2013
Messages
10,368
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
 

NRGZ

New member
Local time
Today, 14:46
Joined
Aug 9, 2021
Messages
15
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:46
Joined
May 7, 2009
Messages
19,233
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

Top Bottom