Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2007, 04:54 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default check box problem

Got another problem again...

I have a form where I have set up 15 different check boxes.What I would like to have is that when none of those 15 has been checked, the user gets a message box that he has to check at least 1 of these 15 check boxes.

The code I have written for that part of the code is:

'check if at least 1 check box has been checked
If Me.CheckBA01.Value = False _
    And Me.CheckBA02.Value = False _
    And Me.CheckBA03Bed.Value = False _
    And Me.CheckBA03Pax.Value = False _
    And Me.CheckBA04.Value = False _
    And Me.CheckBA05.Value = False _
    And Me.CheckBA06.Value = False _
    And Me.CheckBA08Bed.Value = False _
    And Me.CheckBA08Textil.Value = False _
    And Me.CheckBA09.Value = False _
    And Me.CheckBA10.Value = False _
    And Me.CheckBA40.Value = False _
    And Me.CheckBA50.Value = False _
    And Me.CheckFamily.Value = False _
    And Me.CheckZB.Value = False Then
    MsgBox "Gelieve minstens 1 afdeling aan te vinken." & vbCrLf & _
    "Veuillez choisir au moins 1 département.", vbExclamation
    Exit Sub
End If

but this isn't working. Does anyone knows why? The box is empty so the value is false. Just don't get why this is not working...

 
Old March 1st, 2007, 08:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I think you will find that if the check box has never been checked, it returns a Null, and not a False. I think a False requires checking and then unchecking a check box. So check for False and Null for each one instead of just False.

Did that help?

mmcdonal
 
Old March 1st, 2007, 03:10 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added

And Isnull(me.checkBA01) and Isnull(me.checkBA02)...

to the code but it didn't change a thing...

I also tried to replace everything to

'check if at least 1 check box has been checked
If Me.CheckBA01.Value = "" And Me.CheckBA02.Value = "" And Me.CheckBA03Bed.Value = "" _
    And Me.CheckBA03Pax.Value = "" And Me.CheckBA04.Value = "" And Me.CheckBA05.Value = "" _
    And Me.CheckBA06.Value = "" And Me.CheckBA08Bed.Value = "" And Me.CheckBA08Textil.Value = "" _
    And Me.CheckBA09.Value = "" And Me.CheckBA10.Value = "" And Me.CheckBA40.Value = "" _
    And Me.CheckBA50.Value = "" And Me.CheckFamily.Value = "" And Me.CheckZB.Value = "" Then
    MsgBox "Gelieve minstens 1 afdeling aan te vinken." & vbCrLf & _
    "Veuillez choisir au moins 1 département.", vbExclamation
    Exit Sub
End If

but this didn't work either... If this is not possible to do it is not too dramatic.
I thought I could use this to be sure a check box had been checked. However, now the user will get the message box from the end of the code that tells him the record has been added for the selected department. None of them is chosen, so none of them has been added... This is not a lie, but just a little bit stupid. Getting a message box that tells you to records have been added, while nothing happened because you didn't make a choice in the check boxes...

 
Old March 1st, 2007, 04:35 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Okay, try removing the .Value from the code, or try this:

Create a module, and put this in it:

Public NoCheck As Boolean

Then, on the on load event of the form, put this:

NoCheck = False

Then on each of the check boxes on click event put this:

NoCheck = True

Then check this value. This won't work all the time since they can check and uncheck and this will still be true. I will take a look tomororow. This should be easy.



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
check box help? dstein4d Access VBA 2 February 27th, 2008 09:54 AM
Check BOx kaushikpulpa ASP.NET 2.0 Professional 2 August 30th, 2007 08:01 AM
Problem inserting value from Check Box vivekshah C# 3 June 8th, 2006 08:17 AM
check box problem Scripts82 Access VBA 4 April 19th, 2006 03:48 AM
problem reciving check box values using post metho method Pro PHP 1 March 10th, 2006 08:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.