Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why message box isn;t working

Posted on 2014-11-21
12
Medium Priority
?
147 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 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 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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