[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Message on a button in Access 2003 form

Posted on 2012-03-19
15
Medium Priority
?
308 Views
Last Modified: 2012-03-20
Hi experts,

Below is my goal, of course it doesn't work for me like this. Could you please help?

Private Sub Command29_GotFocus()

If A=B
Then MsgBox ("Budget OK")
else MsgBox ("Please check Budget")
End if

End Sub

Thank you!
0
Comment
Question by:howruaz9
[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
  • +1
15 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 37739590
So, what doesn't work? No messages ?

Try the click event
Private Sub Command29_Click()

If A=B Then
     MsgBox ("Budget OK")
else
      MsgBox ("Please check Budget")
End if

End Sub
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739609
<doesn't work>
?

Can you post the *entire* code please, then clearly state what does, or does not happen?

Also, are you quite sure the GotFocus event is the best event for this?
(Seems to me like BeforeUpdate or AfterUpdate, of a control might be better)

This is why it is always best if you *First* explain, in detail, what your ultimate goal is ...
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 37739612
no points please.

Agree with MX that you should be using the Click event.  I like to keep my code short, so I would probably use:

Private sub cmd_YourCommandButtonName_Click

    msgbox iif(A=B, "Budget OK", "Please check budget!")

End sub
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739620
...Or in the *Click* event of the button....

As the Gotfocus event of the button is rarely used for things like this...
0
 

Author Closing Comment

by:howruaz9
ID: 37739623
Hi MX, it's working on click. Thank you so much!
0
 

Author Comment

by:howruaz9
ID: 37739668
Hi boag2000 and fyed, you both figured out my problem as MX did. Thank you so much for your time, and I wish I could give some points. And I've tried fyed's, it's working perfectly too.
Thanks again.
0
 
LVL 75
ID: 37739707
You are welcome ...

mx
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 37739747
howruaz9,

mx's code is easier to read, if you don't know what you are looking at or are new to VBA, so that is probably your best solution.

I've been writing and maintaining code for so long, I tend to take shortcuts.  The problem with shortcuts is that you have to understand the pro's and con's.  In this case, the IIF() function has a interesting characteristic that when the function is evaluated both the True and False expressions are evaluated, and if either of those expressions would generate an error, then the error is raised.  So, the following expression would raise an error, even though the first expression evaluates to True, and should return (0.75)

A = 3
B = 4
C = 0

?iif(B>A, A/B, B/C)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37739751
howruaz9,

<I wish I could give some points. >

No crybabies here...

;-)

Jeff
0
 

Author Comment

by:howruaz9
ID: 37739846
Hi fyed,

I'm new to VBA, and not sure that I fully understand the following part. I've applied your IIF() Function to on click. Do I need to do something?
A = 3
B = 4
C = 0

?iif(B>A, A/B, B/C)

Thank you very much!
0
 
LVL 75
ID: 37739859
Let's keep it simple here guys. I realize that is a 'trick' solution, but come on ...

mx
0
 

Author Comment

by:howruaz9
ID: 37739868
Hi Jeff,

Your posts always make me think, if they don't, they makes me laugh......
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 37740386
howruaz9,

Sorry for the confusion.  Use mx's solution, it is the simplest and is easy to read.

I was attempting to impart some additional knowledge, and just muddied the waters.

Like I said above:

"mx's code is easier to read, if you don't know what you are looking at or are new to VBA, so that is probably your best solution."
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37740531
<Hi Jeff,
Your posts always make me think, if they don't, they makes me laugh......>

Made My Day!
;-)

Jeff
0
 

Author Comment

by:howruaz9
ID: 37742303
Thanks, fyed. It's always good to know more. No need to say sorry. For now, just like mx and you suggested, I'm using the simpliest solution to make the database work.

Thanks, everyone.
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.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

649 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