Solved

Why message box isn;t working

Posted on 2014-11-21
12
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 51

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 51

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 51

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 51

Accepted Solution

by:
Gustav Brock earned 500 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 51

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

Technology Partners: 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!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

617 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