Issue with numbers in textboxes not comparing against each other (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 11:14
Joined
Dec 1, 2014
Messages
401
Hi

I am creating an edit form whereby i can change the volume of compost a pot can hold. What i am trying to do is stop the person editing a pot size by by putting in the existing pot volume.

I have the following code:

Code:
If Me.Txt_NewVolume = Me.Txt_CurrentVolume.Value Then
        
        msg = "This is the same compost volume that already exists with this potsize!!!"
        style = vbOKOnly + vbExclamation
        title = StrTier1 & " Duplicate Error"

        response = MsgBox(msg, style, title)

Issue is me.currentvolume value when triggered will equal for example 3 but the me.txt_NewVolume will equal "3" so the if statement is not triggering.

Got me very confused.

Thansk in advance.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:14
Joined
May 21, 2018
Messages
8,463
Not really sure how you are setting this up, but maybe compare the two strings.
cstr(Me.Txt_NewVolume) = cstr(Me.Txt_CurrentVolume.Value)
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:14
Joined
Jan 23, 2006
Messages
15,364
?? I'm confused too ??
Perhaps you could give us a little more detail -in plain English -dealing with
- why a Pot size should/could change?
- what limits the size value involved? vetting/validation/logic check
- who should be making any changes to pot size
 

missinglinq

AWF VIP
Local time
Today, 07:14
Joined
Jun 20, 2003
Messages
6,423
...Issue is me.currentvolume value when triggered will equal for example 3 but the me.txt_NewVolume will equal "3"
If txt_NewVolume is a string, i.e. "3" then it must be defined as Text...it needs to be defined or at least Formatted as a Number. Is txt_NewVolume bound to a Field in the underlying Table?

Linq ;0)>
 

HalloweenWeed

Member
Local time
Today, 07:14
Joined
Apr 8, 2020
Messages
213
If txt_NewVolume is a string, i.e. "3" then it must be defined as Text...it needs to be defined or at least Formatted as a Number. Is txt_NewVolume bound to a Field in the underlying Table?

Linq ;0)>
Or you need to convert to a number like "Val(me.txt_NewVolume)" etc. then compare. Note this method will fail when a user enters something other than a number, any other characters, so this method is not recommended. Just telling you to help your understanding.

Also, wondering where you get me.txt_NewVolume and Me.Txt_CurrentVolume. There is no need to add ".Value" as it is the default property. Are you using [Potsize].Text within an "on change" event to get me.txt_NewVolume? And/or are you using [Potsize].Value within same event to get Me.Txt_CurrentVolume? You can only use ".Text" when the control has the focus.
 

Users who are viewing this thread

Top Bottom