Checking two text box values with if condition (1 Viewer)

shan_vba

New member
Local time
Tomorrow, 03:57
Joined
Mar 14, 2020
Messages
21
In my small application There is a text box called TAKE OUT where user can enter a value and click the button so it will be deduced from the Quantity text box (Which is bound to the database) and this should happen only if the TAKEOUT value is smaller than the quantity other wise a message should appear I added the following code to the button but it always gets the message (even if the take out value is smaller)

If Me.txt_OUT.Value > Me.txt_qty.Value Then
MsgBox ("Stock quantity not enough")
Else
Me.txt_qty.Value = Me.txt_qty.Value - Me.txt_OUT.Value
Me.txt_OUT.Value = ""
End If

Please help me I'm new to access
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:27
Joined
Oct 29, 2018
Messages
21,521
Hi. Just a guess, but try something like:

If Val(Me.txt_OUT)>Val(Me.txt_qty) Then
 

vba_php

Forum Troll
Local time
Today, 17:27
Joined
Oct 6, 2019
Messages
2,880
you're ALWAYS getting a message regardless of what's in the boxes? It sounds to me like you are confused. if both boxes have numeric data types in them, your code should work fine i would think. but in your ELSE statement, you have this:
Code:
Me.txt_OUT.Value = ""
you are assigning a 0-length string to the box's value. I'm not even sure you can do that if it is set in the properties to be a *number*. data types exist for this very reason. because they are different sizes, serve different purposes, etc... so you can't mix them up, in general. they are "seperatists". kind of like Trump and the democrats. :p
 

shan_vba

New member
Local time
Tomorrow, 03:57
Joined
Mar 14, 2020
Messages
21
you're ALWAYS getting a message regardless of what's in the boxes? It sounds to me like you are confused. if both boxes have numeric data types in them, your code should work fine i would think. but in your ELSE statement, you have this:
Code:
Me.txt_OUT.Value = ""
you are assigning a 0-length string to the box's value. I'm not even sure you can do that if it is set in the properties to be a *number*. data types exist for this very reason. because they are different sizes, serve different purposes, etc... so you can't mix them up, in general. they are "seperatists". kind of like Trump and the democrats. :p
It worked Thanks a lot but it's wierd..... because those values are not strings as they could calculated instead of concatenated and even it worked when I was checking for 0 But any way I couldn't have figure it out without your advise....
 

vba_php

Forum Troll
Local time
Today, 17:27
Joined
Oct 6, 2019
Messages
2,880
It worked Thanks a lot but it's wierd..... because those values are not strings as they could calculated instead of concatenated and even it worked when I was checking for 0 But any way I couldn't have figure it out without your advise....
well thanks, but i'm not the best around here. regardless though, good luck. =)
 

shan_vba

New member
Local time
Tomorrow, 03:57
Joined
Mar 14, 2020
Messages
21
It worked Thanks a lot but it's wierd..... because those values are not strings as they could calculated instead of concatenated and even it worked when I was checking for 0 But any way I couldn't have figure it out without your advise....
It was the same without Me.txt_OUT.Value = "" I added it as things were not working to see (A guess)
 

vba_php

Forum Troll
Local time
Today, 17:27
Joined
Oct 6, 2019
Messages
2,880
It was the same without Me.txt_OUT.Value = "" I added it as things were not working to see (A guess)
the code I referenced had nothing to do with your issue. r u still having problems solving things?
 

Users who are viewing this thread

Top Bottom