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 July 31st, 2006, 08:53 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checkboxes and continuous forms

I have a continuous form that's bound to a table. While I don't have a yes/no field (It's Yes/No/Not Applicable - 3 way, so it's text), I put 3 checkboxes, and an invisible textbox control that's bound. It looks something like this: (The column with no text is the invisible, bound textbox).

Code:
+--------------------+----------+
| Yes | No | N/A |   | Comments |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [      ] |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [      ] |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [      ] |
+-----+----+-----+---+----------+
Now, I have a few issues. First, the checkboxes appear grayed out, but I can still click in them. However, when I do, all checkboxes are selected. I also have code that unchecks the other checkboxes, too, so I want to make sure I'm only checking one. I tried something like chkYes(1) = False, but Access didn't like it. (Unfortunately, there's not chkYes.Item(...), either...)

Anyway, what I want it to do is, when checked, write the value (1,0,-1) in the invisible bound textbox for that record only, not all of them. Is there anyway to do this?

Also, the last textbox (bound) that I put in won't let me edit it. I also have labels (really textboxes) that are bound - I can't find a way to bind labels - and even though I have them as disabled, it looks like I could edit them...

(Yet more reasons why I like C++ and .NET better.)


EDIT:

I found out that the check box does have a 3-state setting, so I'm working with that, and a label to show yes/no/NA. Now I can't even check or uncheck it... (Seems the whole form won't let me edit, even though the edit property is selected) If I have the "Form" property of "Data Entry" selected, nothing shows up - the detail section is blank. Granted, I'm hoping NOT to use this method...
 
Old July 31st, 2006, 09:13 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

One of the little quirks with Access is that you can't use control arrays. There are ways around this, but for this application I would do something like this...

Private Sub chkBox1_Click()
    If chkBox1 = -1 then
        chkBox2 = 0
        chkBox3 = 0
        txtComments = 1
    end if
End sub

That is probably a little clunky, and you would have to do the same for the other boxes, but it'll work, or it might give you an idea to get something better.

The best way I have found around control arrays is to name them with incremental numbers and then use Form.Controls.Name("myControl" & i) where i is the number you want to call.

HTH

Mike


Mike
EchoVue.com
 
Old July 31st, 2006, 12:38 PM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a similar method of doing that for the checkboxes, but the problem is, it puts the check for all checkboxes.

i.e.

Before:

+--------------------+----------+
| Yes | No | N/A | | Comments |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+
| [ ] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+

After:

+--------------------+----------+
| Yes | No | N/A | | Comments |
+-----+----+-----+---+----------+
| [x] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+
| [x] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+
| [x] | [ ]| [ ] + []| [ ] |
+-----+----+-----+---+----------+

If I check "Yes" in one row, it puts "Yes" in all rows.

I'm not sure if I can give them control names, since they're bound. (I'd upload a sample database if there was somewhere I could upload a file)

 
Old August 3rd, 2006, 07:46 AM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

The reason that your checkboxes are all greyed out is that they have no values assigned to them, either by your code or in the Checkbox.DefaultValue property. As they are unbound, Access will always change all check boxes in a 'column' to the same value as the current record. The way around this is messy, but quite straightforward.

Suppose that the text field holding the values for Yes/No/Not applicable in the underlying table is called TextField which holds the corresponding values 1,2,3. In each Checkbox's Control Source you will need an If statement along the lines =Iif([TextField] = 1,-1,0) in the Yes column, similarly =Iif([TextFiled] = 2,-1,0) in the No column and so on. Behind each Checkbox's After Update event you will need code to write back the changed value to the underlying table, and then refresh the screen. I am never sure whether to use Form.Refresh, Form.Requery or Form.Repaint, so generally I use them all - just in case! As it is only three checkboxes, this won't be too bad, I just had to do it for 24!

Good luck
 
Old August 3rd, 2006, 09:47 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just found a work-around for this. If I use a frame, I can bind the data to the field I want. Any checkbox or radio button value that is changed inside of the frame will not only affect just that record (which I want), it also affects the field I want to change.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating Continuous Forms Bobbyworld Access VBA 8 May 13th, 2007 03:28 AM
continuous forms question hamffjs Access 3 January 29th, 2007 01:33 PM
Continuous Forms Issues strikeuk Access 1 January 2nd, 2006 11:59 AM
Counting Checkboxes On A Continuous Subform PC User Access VBA 4 April 26th, 2005 09:26 PM
Continuous Forms Ben Access VBA 2 February 17th, 2004 10:34 AM





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