Solved

Why message box isn;t working

Posted on 2014-11-21
12
138 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
Comment Utility
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
Comment Utility
Which event are you using to run the code?
0
 

Author Comment

by:SteveL13
Comment Utility
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
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Try deleting the code and rewrite it.

/gustav
0
 

Author Comment

by:SteveL13
Comment Utility
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
Comment Utility
It should work.
Try using Val() on both the values.

/gustav
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 84
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You are welcome!

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now