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

chrisjames25

Registered User.
Local time
Today, 22:33
Joined
Dec 1, 2014
Messages
339
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, 17:33
Joined
May 21, 2018
Messages
3,183
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, 17:33
Joined
Jan 23, 2006
Messages
13,199
?? 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, 17:33
Joined
Jun 20, 2003
Messages
6,370
...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, 17:33
Joined
Apr 8, 2020
Messages
87
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 (Users: 0, Guests: 1)

Top Bottom