Wrox Programmer Forums
|
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference 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 30th, 2014, 08:44 PM
Registered User
 
Join Date: Mar 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom CheckBox troubles

On a form I will have a dozen or more checkboxes that determine if specific documents are required for this client. Each checkbox will have "associated" with it one or more other controls that hold data about when that document was sent, received, the score, etc.

The goal is to have the checkbox's AfterUpdate event Sub set the .enabled value of the associated controls ("Friends") on or off to match the checkbox's status.

The authors of Microsoft Access 2010 Programmer's Reference suggest creating a subclass of the standard checkbox object which allows you to add another parameter (.Friends) which is an array of the form's controls that are associated with each instance of the checkbox object.

Here's where I'm stuck
First when assigning the array of objects to the subclassed checkbox object's .Friends parameter. In the "Public Property Let Friends(oArray As Variant)" on the next line I get: "Can't assign to an array"

Second I'm not sure I'm passing the associated object reference in the right way (in the form's OnOpen event Sub) so as to be able to use them in the custom class's "mCkBx_AfterUpdate()".

Here is the code from 1) the form's VBA code and 2) the class module.


Code:
Option Compare Database
Option Explicit
Public mCK01 As New clsMyCkBox

Private Sub Form_Open(Cancel As Integer)
  'Setup all the CheckBox classes
  Set mCK01.sjrCkBox = Me.ckDocA
  
  'Set the .Friends array for each special checkbox (those obj's that get turned on & off with this checkbox)
  Dim aAr(2) As Variant
  aAr(0) = "Me.txtDocADtSent"    'or should this be "Form_frmDocControl.txtDocADtSent" ??
  aAr(1) = "Me.txtDocADtRecvd"
  mCK01.Friends = aAr
End Sub

Private Sub Form_Unload(Cancel As Integer)
   'Cleanup special Checkbox class instances
  Set mCK01 = Nothing
End Sub

Code:
Option Compare Database
Option Explicit

'Declare the class instance
Private WithEvents mCkBx As CheckBox
'The private variable behind the Friends parameter (dimensioned smaller than will be in the final application)
Private maFriends(2) As Variant

Public Property Get sjrCkBox() As CheckBox
  Set sjrCheckBox = mCkBx
End Property

Public Property Set sjrCkBox(objCkBx As CheckBox)
  Set mCkBx = objCkBx
  mCkBx.AfterUpdate = "[Event Procedure]"
  
End Property

Public Property Let Friends(oArray As Variant)
  maFriends = oArray
End Property

Private Sub mCkBx_AfterUpdate()
  Dim bOn As Boolean
  Dim i As Integer
  
  bOn = Me.sjrCkBox.Value
  For i = 0 To UBound(maFriends)
    'set the enabled value for each object to match the Checkbox value
    maFriends(i).Enabled = bOn
  Next
End Sub
 
Old April 2nd, 2014, 11:16 AM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi sjr1917,

Using your code slightly modified please try this:

Form code:

Code:
Option Compare Database

Option Explicit

Public mCK01 As New clsMyCkBox

Private Sub Form_Open(Cancel As Integer)
  'Setup all the CheckBox classes
  Set mCK01.sjrCkBox = Me.CkDocA
  
  'Set the .Friends array for each special checkbox (those obj's that get turned on & off with this checkbox)
  Dim aAr(1) As Variant
  Set aAr(0) = Me.txtDocADtSent    'or should this be "Form_frmDocControl.txtDocADtSent" ??
  Set aAr(1) = Me.txtDocADtRecvd
  mCK01.Friends = aAr
End Sub

Private Sub Form_Unload(Cancel As Integer)
   'Cleanup special Checkbox class instances
  Set mCK01 = Nothing
End Sub
Class Code:

Code:
Option Compare Database

Option Explicit

'Declare the class instance
Private WithEvents mCkBx As CheckBox
'The private variable behind the Friends parameter (dimensioned smaller than will be in the final application)
Private maFriends As Variant

Public Property Get sjrCkBox() As CheckBox
  Set sjrCkBox = mCkBx
End Property

Public Property Set sjrCkBox(objCkBx As CheckBox)
  Set mCkBx = objCkBx
  mCkBx.AfterUpdate = "[Event Procedure]"
  
End Property

Public Property Let Friends(oArray As Variant)
  maFriends = oArray
End Property

Private Sub mCkBx_AfterUpdate()
  Dim bOn As Boolean
  Dim i As Integer
  
  bOn = Me.sjrCkBox.Value
  For i = 0 To UBound(maFriends)
    'set the enabled value for each object to match the Checkbox value
    maFriends(i).Enabled = bOn
  Next
End Sub
HTH

Malc.
 
Old April 2nd, 2014, 01:31 PM
Registered User
 
Join Date: Mar 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default That did it!

Thanks, Malcolm. Forgot the "Set" for object assignment.
Works great.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubles with Programm AlisaSmi Excel VBA 0 March 7th, 2007 07:50 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
CurrentRegion troubles Glen Frank Excel VBA 2 July 20th, 2005 07:04 AM
DataGrid Troubles mrideout BOOK: Beginning ASP.NET 1.0 1 August 17th, 2004 11:32 AM
Interop Troubles Yehuda Pro VB.NET 2002/2003 0 June 29th, 2004 01:26 PM





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