Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why message box isn;t working

Posted on 2014-11-21
12
Medium Priority
?
149 Views
Last Modified: 2014-11-22
I have this code in the afterupdate event of a field, Me.txtHeightInFeet   -- But the message box isn't appearing if I enter 9 and txtMaxHeightInFeet  = 8.

????

    If Me.txtHeightInFeet > Me.txtMaxHeightInFeet Then
        MsgBox "The height you entered is greater than the maximum height for this product."
    End If
0
Comment
Question by:SteveL13
  • 5
  • 4
  • 3
12 Comments
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40457962
Try this code to debug:


     MsgBox "HIF: '" & Me.txtHeightInFeet & "' - MHIF: '" & Me.txtMaxHeightInFeet & "'"
     If Me.txtHeightInFeet > Me.txtMaxHeightInFeet Then
         MsgBox "The height you entered is greater than the maximum height for this product."
     End If

and you'll see.

/gustav
0
 
LVL 85
ID: 40458092
Which event are you using to run the code?
0
 

Author Comment

by:SteveL13
ID: 40458106
Using Gustav code I get this...

Message Box
So I don't know why the message box isn't appearing if I enter 9 and txtMaxHeightInFeet  = 8

I'm using the afterupdate event of Me.txtHeightInFeet
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40458208
Try deleting the code and rewrite it.

/gustav
0
 

Author Comment

by:SteveL13
ID: 40458253
I deleted the code.  Compiled.  Compact and Repair.  Re-wrote the code and it still didn't work.  So I changed the code to:

    If Me.txtHeightInFeet > DLookup("[MaxPanelHeightInFeet]", "tblProducts", "[ProductID] = " & Forms!frmProjectCalculation!cboProductID) Then
        MsgBox "The height you entered is greater than the maximum height for this product."
    End If

And it works.  Rather than have txtMaxHeightInFeet  come from an afterupdate event of a combo box I incorporated the DLookup.

But I still  don't know why the original code didn't work.

??
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40458308
It should work.
Try using Val() on both the values.

/gustav
0
 
LVL 85
ID: 40459111
Rather than have txtMaxHeightInFeet  come from an afterupdate event of a combo box I incorporated the DLookup.
If you're using a Combo, you may need to be sure you're referring to the correct column. For example, if your combo has a RowSource like this:

SELECT ID, YourValue FROM YourTable

And you wanted to use the value from the "YourValue" column, you'd have to refer to the second column:

If Me.Textbox1 > Me.Combo1.Column(1)

Also a good reason to use nameing conventions. A combo would typically be named "cboMaxValue" or something like that.
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 40459115
But as you can see from my messagebox, this is not the case; the values are real and present.

To me it should work. Still, values are strings, thus I suggested this:

    If Val(Me!txtHeightInFeet) > Val(Me!txtMaxHeightInFeet) Then

That would force a numeric comparison of 9 > 8.

/gustav
0
 

Author Comment

by:SteveL13
ID: 40459420
This worked...

If Val(Me!txtHeightInFeet) > Val(Me!txtMaxHeightInFeet) Then

Also, I had tried the combobox column  with me.cboProductID.column(5) (actually the 5th column, and it still didn't work.
0
 

Author Closing Comment

by:SteveL13
ID: 40459421
This solution worked but the whole thing still puzzles me as to why the other attempts didn't work.  But for now, all is good.  Thank you.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40459422
You are welcome!

/gustav
0
 
LVL 85
ID: 40459426
But as you can see from my messagebox, this is not the case; the values are real and present.
Ahhh ... I skimmed over that. Of course gustav is right, just saw the Combo mention and know that often this can be a trouble spot.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question