IF is not working on unbound form.

awa786

Registered User.
Local time
Today, 11:03
Joined
Jul 7, 2015
Messages
23
Hi all, help needed!
I am facing a problem that if is not working is not working on unbound form.
code and sample file is attached.
when transaction amt is equal to voucher amt then do nothing else msgbox but not working.
Regards.

Code:
Private Sub Tran_Amt_AfterUpdate()
If Me.Tran_Amt = Me.Voucher_Amt Then
'Do nothing
Else:
MsgBox "You have entered less then Voucher amount."
Tran_Amount = Null

End If
End Sub
 

Attachments

1. you don't need the colon on the ELSE
2. are you SURE the 2 box names are spelled correctly. NOT the field name, the text box name.


otherwise it should work.
 
1. you don't need the colon on the ELSE
2. are you SURE the 2 box names are spelled correctly. NOT the field name, the text box name.
otherwise it should work.

Textbox names are correct. and i remove the colon but condition is not working
for example,

Trans amt= 1000
voucher amt=1000

if trans_amt=voucher_amt then
do nothing
else
msgbox"not equal"
end if

problem is when condition is true but if condition is giving wrong results on:
when both amounts are equal or not equal . results are same.
 
To test where the problem is occurring, replace both control's values with specific amounts.
Code:
 Private Sub Tran_Amt_AfterUpdate()
If 1000 = 1000 Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub
If that works, the logic is correct.

Then replace one control's value with a specific amount, type the same amount into the second control and see what happens.
Code:
 Private Sub Tran_Amt_AfterUpdate()
If Me.Tran_Amt = 1000 Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub
If that works, the other control's value AND the logic are correct.

Now replace the remaining control's value with a specific value and type 1000 into the other field.
Code:
 Private Sub Tran_Amt_AfterUpdate()
If 1000 = Me.Voucher_Amt Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub
This allows for all combinations of places where the issue could be occurring and should allow you to narrow down the problem area.
 
dear ALC
i have tried all these combination but the logic is correct. but i am unable to find the solution.
please help me
 
Try this , zero rather than null
Voucher _amt was locked so unlocked it .


#Private Sub Tran_Amt_AfterUpdate()
If Me.Tran_Amt < Me.Voucher_Amt Then


MsgBox "You have entered less then Voucher amount."
Me.Tran_Amt = 0

End If

Regards Yp[ma
End Sub#
 
dear ALC
i have tried all these combination but the logic is correct. but i am unable to find the solution.
please help me
So you've proven the logic to be correct. Now go on to the second and third steps.

If the logic is correct, the problem has to be one or both of the values coming from the two fields.
 
Try this , zero rather than null
Voucher _amt was locked so unlocked it .


#Private Sub Tran_Amt_AfterUpdate()
If Me.Tran_Amt < Me.Voucher_Amt Then


MsgBox "You have entered less then Voucher amount."
Me.Tran_Amt = 0

End If

Regards Yp[ma
End Sub#


i have tried this but can't solved

if condition is true or false results are the same..
MsgBox "You have entered less then Voucher amount."
this will popup in both cases.
 
So you have tried this and it also produces the problem?
Code:
 Private Sub Tran_Amt_AfterUpdate()
If 1000 = 1000 Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub
If not then the logic IS correct and one or more value IS the problem.
 
Dear alc,
Code:
So you have tried this and it also produces the problem?
Code:
 Private Sub Tran_Amt_AfterUpdate()
If 1000 = 1000 Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub
If not then the logic IS correct and one or more value IS the problem.
while using above , nothing happen, no results occurred.

i am still confusing .
i have attached sample again with another form where amount field is bound with table and the same condition is working fine for me.but in form FP321 why not working for me .

can you please check the FP321working form where same condition is working .
 

Attachments

The security settings here prevent me from downloading your attachment, but the first sentence there is a good clue: when you hard-code values in (1000 = 1000) nothing happens. This is what you want to happen, so it suggests your logic (the comparison being made) is sound. This tells us the problem is with the value(s) you're passing in to it.

Now try replacing one of the 1000 value with the actual field and retest.
If you still get nothing happening, then try it replacing the other 1000 with the field name and retest.
This will show you exactly which field or fields are causing the problem.
 
Code:
Private Sub Tran_Amt_AfterUpdate()
If Me.Tran_Amt = 1000 Then

Else
MsgBox "You have entered less then Voucher amount."


End If
End Sub

working




and this
Code:
 Private Sub Tran_Amt_AfterUpdate()
If 1000 = Me.Voucher_Amt Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
     Tran_Amount = Null
End If
End Sub

not working
 
Code:
 Private Sub [COLOR="Red"]Tran_Amt[/COLOR]_AfterUpdate()
If 1000 = Me.Voucher_Amt Then
     'Do nothing
Else:
     MsgBox "You have entered less then Voucher amount."
    [COLOR="Red"] Me.[/COLOR] [COLOR="SeaGreen"]Tran_Amount[/COLOR] = Null
End If
End Sub

not working

You aren't setting the right thing to null which probably isn't helping your testing. The sub refers to a control Tran_Amt In red. You are then trying to set something called Tran_Amount (in green) to null. And you appear to have missed of the Me. in front of it as well.
 
Good. So we now know that the field Me.Voucher_Amt is the problem.
Try putting a message box right before the check and see if it is actually set to what you're expecting
Private Sub Tran_Amt_AfterUpdate()
msgbox Me.Voucher_Amt
If 1000 = Me.Voucher_Amt Then
'Do nothing
Else:
MsgBox "You have entered less then Voucher amount."
Tran_Amount = Null
End If
End Sub
 
Good. So we now know that the field Me.Voucher_Amt is the problem.
Try putting a message box right before the check and see if it is actually set to what you're expecting
Private Sub Tran_Amt_AfterUpdate()
msgbox Me.Voucher_Amt
If 1000 = Me.Voucher_Amt Then
'Do nothing
Else:
MsgBox "You have entered less then Voucher amount."
Tran_Amount = Null
End If
End Sub

Code:
Private Sub Tran_Amt_AfterUpdate()
MsgBox "voucher amount is =" & Me.Voucher_Amt
MsgBox "transaction amount is =" & Me.Tran_Amt

If Me.Tran_Amt = Me.Voucher_Amt Then
'Do nothing
Else:
MsgBox "You have entered less then Voucher amount."

End If
End Sub
i have try to put a message box right before the both values to check and see that both are that i am expecting but IF condition is giving me wrong results.
 
Is one value text and one numeric? They'd look the same to you or I but comparisons wouldn't find a match. In particular, Me.Voucher_Amt 9as this is the field that didn't get a match against the hard coded value of 1,000.

As a quick test, see if this works:
Code:
 Private Sub Tran_Amt_AfterUpdate()
MsgBox "voucher amount is =" & Me.Voucher_Amt
MsgBox "transaction amount is =" & Me.Tran_Amt

If Me.Tran_Amt = Val(Me.Voucher_Amt) Then
'Do nothing
Else:
MsgBox "You have entered less then Voucher amount."

End If
End Sub
If you now get a match, you know the value is set up as text.
 
Since you say this is an unbound form, that means that the .Controlsource for the two text boxes will be empty. The two boxes start life as NULL, because all controls are of type Variant, and a Variant can be null before its first definition (I think). To prevent from getting whacked by this, do the following:
Code:
If NZ( Me.Tran_Amt, 0) = NZ( Me.Voucher_Amt, 0) Then

You don't show it in your code, but the place where Tran_Amt is defined should be carefully inspected to verify that it doesn't set something incorrectly, since it is also unbound.
 
If Me.Tran_Amt = Val(Me.Voucher_Amt) Then
this wroks...........
Thanks ALC & all of you for your kind support on this issue.
Thanks & Best Regards
 

Users who are viewing this thread

Back
Top Bottom