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
Solved

Why message box isn;t working

Posted on 2014-11-21
12
142 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 49

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 84
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 49

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 49

Expert Comment

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

/gustav
0
 
LVL 84
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 49

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 49

Expert Comment

by:Gustav Brock
ID: 40459422
You are welcome!

/gustav
0
 
LVL 84
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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