Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 February 17th, 2005, 06:29 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default testing variables in a function

Hi

I am trying to test the value of four check boxes which will determine the value of x ie if chk1 = -1 and chk2 = -1 and chk3 = -1 and chk4 = -1 then x=5. I thought about calculating this within a function but keep getting the message Argument not optional. Anyone any ideas?

Cheers
Tony
__________________
Cheers
Tony
 
Old February 17th, 2005, 09:07 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Here is a quick and dirty way to do this:

I created a form with 5 check boxes, and one text box. I let Access name them, hence Check0, Check2, etc.

I put this code on the Form's On Current event, and on each of the check boxes After Update events.

When I check or uncheck a box, the text box immediately shows the tally:

'==========
    Dim chk0 As Long
    Dim chk2 As Long
    Dim chk4 As Long
    Dim chk6 As Long
    Dim chk8 As Long
    Dim lgText As Long

    If Check0 = -1 Then
        chk0 = 1
        Else: chk0 = 0
    End If

    If Check2 = -1 Then
        chk2 = 1
        Else: chk2 = 0
    End If

    If Check4 = -1 Then
        chk4 = 1
        Else: chk4 = 0
    End If

    If Check6 = -1 Then
        chk6 = 1
        Else: chk6 = 0
    End If

    If Check8 = -1 Then
        chk8 = 1
        Else: chk8 = 0
    End If

    lgText = chk0 + chk2 + chk4 + chk6 + chk8

    Me.Text10 = lgText
'==========

HTH

mmcdonal
 
Old February 17th, 2005, 09:46 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mmcdonal

My fault, you've picked up the question wrong but this was due to the shortness of my question. The -1 for the checkbox means the user has ticked it and a zero means the user hasn't. I have 4 tickboxes and the user can tick a possible of 6 feasible combinations ie chkBox1 ticked, chkBox2 unticked, chkBox3 unticked and chkBox4 ticked. Therefore chkBox1 = -1, chkBox2 = 0, chkBox3 = 0 and chkBox4 = -1.
I would like to store this combination as a single value ie x = 4 and then use this value to determine what boxes have been ticked. Any ideas?



Cheers
Tony





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unit Testing userrob BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 9th, 2005 10:35 AM
Is it better to pass variables to a function? stephen_c_ Beginning PHP 3 November 4th, 2005 05:07 AM
Returning variables from a function starsol Beginning PHP 1 September 11th, 2003 12:58 PM
Looping through variables, Applying a function tdaustin Classic ASP Basics 0 August 3rd, 2003 07:50 PM
testing mark C# 0 June 4th, 2003 08:37 PM





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