If Statement not working

G

Gabby Girl

Good morning,

Could someone please help me with why the following If Statement is not
working?

Private Sub HourmeterStart_BeforeUpdate(Cancel As Integer)

If Me.HourmeterStart < Me.MaxHMR AND Me.HasMeter = True Then
MsgBox "This hourmeter is less than the last hourmeter!" & Chr(10) & Please
verify meter reading.", vbOkOnly, "Stop!"
Cancel = True
Me.HourmeterStart.Undo

End If

End Sub
*************************

Even if the current meter being entered is greater than the last meter
reading we get the MsgBox error. I've checked all tables, queries involved
and there are no previous readings that are higher than the current & yet we
still get the message. Is there something missing from my code?

Any help would be greatly appreciated.

Thanks
 
G

Gabby Girl

Hi,

Thanks so much for the reply, but unfortunately that was just a typo on my
part. Actual code on my form is correct. Any other suggestions?

Thanks again for your help.
 
C

Cheese_whiz

Hi Gabby,

Try making it :

If Me.HourmeterStart.text <

If that doesn't work, it may be a problem with data types, but I'm not sure...

CW
 
B

BruceM

What types of fields are HourmeterStart and MaxHMR? Are they both of the
same data type?
 
G

Gabby Girl

Thank You Kingston, BruceM and Cheese_whiz for all your help.

HourmeterStart is a Number data type & MaxHMR is actually a DLookup field
(from a query) and so to tell you the truth I really don't know what data
type that makes it (still pretty new to all this - but Thanks to this
newsgroup learning more each day)

Anyway, Cheeze_whiz your suggestion Me.HourmeterStart.Text fixed the
problem. I don't understand why that is but it did the trick so why question
it!

Again Thank you so much to all of you.
 
C

Cheese_whiz

Glad it helped, Gabby.

It comes down to when the data you are trying to reference was added. If
you go to a record and type in a new entry for a textbox, that's considered
to be an 'uncommitted' value (read: unsaved). Until you do something to
'commit' the value, you have to refer to it using the .text property.

Navigating to a new record, closing the form, running appropriate vba code,
etc. will all commit the value, after which you don't need the .text anymore.

Hope that helps,
CW
 
G

Gabby Girl

Hi CW,

Yes that helped alot. I really do prefer to understand how things work.

Thanks again. I really appreciate all your help/expertise.
Have a great day.

Gabby
 
Top