Solved

IF then statement with a message box

Posted on 2007-03-21
13
332 Views
Last Modified: 2013-11-27
I am trying to write some code that says - if a text box (which sums the number of yes/no boxes) is greater than 3, bring up a message box.

Problem:  it's not warning me if I go over 3

If (Me.Text49 > 3) Then
    MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancell = True
End If
0
Comment
Question by:dewster1971
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 26

Expert Comment

by:jerryb30
ID: 18766523
Add msgbox  Me.Text49  before IF statement, and see what values shows up.
0
 

Author Comment

by:dewster1971
ID: 18766589
Jerry -
I don't understand what you're saying here.  Can you rewrite the code so I can understand?
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 18766702
msgbox  Me.Text49  <add this line, wherever your code is at.
Want to make sure you are getting value you think you should.
If (Me.Text49 > 3) Then
    MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancell = True
End If

If you are summing the values of the yes/no boxes, you might be getting a negative number.
0
 
LVL 13

Expert Comment

by:wiswalld
ID: 18773522
If Me.Text49 > 3 Then
    MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancell = True
End If

0
 
LVL 26

Expert Comment

by:jerryb30
ID: 18773567
Can you post the full sub?
adding:
msgbox  Me.Text49  
to the beginning of your sub will allow you to see what value is actually being evaluated in your
 if statement.
0
 
LVL 13

Expert Comment

by:adraughn
ID: 18774900
you had two ll's in cancel.
Msgbox me.Text49 ' Take this out after you get it working
If (Me.Text49 > 3) Then
    MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancel = True
End If
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:dewster1971
ID: 18800615
Sorry for not getting back sooner, but..

Here's what looks like is happening.  My complete code is:

Private Sub HCFASubmit_Click()


If Me.Text49 > 2 Then
    MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancel = True
End If
End Sub

When I clidk the checkbox, the information on the table is updated, and the calculation to sum the check boxes updates (=Sum([HCFASubmit])*-1).  Putting the code

Msgbox me.Text49

returns 1 less than the actual number of checked boxes.  Say two check boxes are checked, I click a 3rd, the Msgbox brings back 2, then I click "OK", the message box goes away and then the Text49 calculation sums to 3.  It's being "delayed" by 1.

Any other suggestions?
0
 
LVL 13

Expert Comment

by:adraughn
ID: 18800667
What is HCFASubmit? Is that a command button? So how I am pocturing this is that you have a form with multiple check boxes, a textbox that adds the value of the checkboxes and a command button that will send the message box. Is that right?

What is the code for the textbox that is calculating the check box totals?

-adria
0
 

Author Comment

by:dewster1971
ID: 18800869
adraughn -
HCFASubmit is a checkbox, the form is tabular and the Text49 text box sums the checkboxes on that form.

The code to sum the checkboxes is: =Sum([HCFASubmit])*-1

I'm not using a command button to initiate the event.  I'm using the "On Click" event for the checkbox to run the event.
0
 
LVL 13

Expert Comment

by:adraughn
ID: 18800886
what are the names of the other check boxes? how many checkboxes fo you have?
0
 
LVL 13

Expert Comment

by:adraughn
ID: 18800966
Private Sub HCFASubmit_Click()
Dim cnt as Integer
cnt = 0
If ckMyCheckBox = True Then cnt = cnt + 1
If ckMyCheckBox2 = True Then cnt = cnt + 1 'etc
   
MsgBox "SELECT CLIENT FIRST"
    Me.HCFASubmit.SetFocus
    Exit Sub
    Cancel = True
End If
End Sub
0
 
LVL 13

Accepted Solution

by:
adraughn earned 50 total points
ID: 18801000
Sorry, I was typing the code into this browser and it submited it for me to early. This is what I was trying to send you:

Private Sub HCFASubmit_Click()
Dim cnt As Integer

cnt = 0
    If Me.ckMyCheckBox = True Then cnt = cnt + 1
    If Me.ckMyCheckBox2 = True Then cnt = cnt + 1 'etc
   
    If cnt > 3 Then
        MsgBox "SELECT CLIENT FIRST"
        Me.HCFASubmit.SetFocus
    Exit Sub
    Cancel = True
End If
End Sub
0
 

Author Comment

by:dewster1971
ID: 18811273
There is only one checkbox and it's called HCFASubmit, but its on a tabular (continuous form) form so it will show up several times.

I finally just put an iif statement on a different command button that runs after a requery.  This seems to do the trick.

Thanks for your help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

19 Experts available now in Live!

Get 1:1 Help Now