Checkbox values at run time

R

Rockn

I am trying to set up a form that will dynamically assign values to
checkboxes that are part of an option group based on the cintents of a
table.

I have set up a test form with six checkboxes and made them all hidden. I
would now like to loop through a recordset and for each record assign a
value to these controls attributes.

visible = true
option.value = PK of the record
label.value = Name of field in record
and loop to the next.

I would think I would also have to count the number of checkboxes to set the
upper bound for the loop and make sure it is not less than the number of
records in the recordset I am looking at.

Any help would be appreciated.
 
C

Charles Wang [MSFT]

Hi Rockn,
I am not sure if I totally understand your meaning. You had six checkboxes
and you said that you need to make sure that the number of checkboxes is
not less than the number of records in the recordset you are looking at. So
I understand that there are must be less than or equal to six records in
your recordset, right?

If this is true, why do not you count the number of the records in the
recordset and then loop through your recordset and dynamically set your
checkboxes properties accordingly?

Please feel free to let me know if I have any misunderstanding or if you
have any other questions or concerns. Have a nice day!


Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
R

Rockn

I am wanting to make sure that the number of checkboxes is not less than the
number of records in the table. If there were to be less checkboxes than the
number of records in the table the correct number of checkboxes would not be
revealed at run time if there was more records.

I am not sure how to loop through the recordset, but I am assuming that I
can use a Do While the count of records does not exceed the number of
controls it will set their properties. How would I dynamically reference the
checkbox controls because they are already named and the values for each are
already set from design view or can you change any control attribute at run
time?

"Charles Wang [MSFT]" said:
Hi Rockn,
I am not sure if I totally understand your meaning. You had six checkboxes
and you said that you need to make sure that the number of checkboxes is
not less than the number of records in the recordset you are looking at.
So
I understand that there are must be less than or equal to six records in
your recordset, right?

If this is true, why do not you count the number of the records in the
recordset and then loop through your recordset and dynamically set your
checkboxes properties accordingly?

Please feel free to let me know if I have any misunderstanding or if you
have any other questions or concerns. Have a nice day!


Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
=========================================================
 
C

Charles Wang [MSFT]

Hi Rockn,
You can save your checkboxes names and labels names into two arrays. Then
you can dynamic set the attributes according to the record loop and the
array index.
For example:
===================================
Public chkList As Variant
Public lblList As Variant


Private Sub cmdLoad_Click()
Dim dbsTest As DAO.Database
Dim rsTasks As DAO.Recordset
Dim strSQL As String
Dim strChkName As String
Dim strLblName As String
Dim intI As Integer

chkList = Array("chk0", "chk1", "chk2", "chk3", "chk4", "chk5")
lblList = Array("lbl0", "lbl1", "lbl2", "lbl3", "lbl4", "lbl5")

On Error GoTo ErrorHandler

Set dbsTest = CurrentDb
strSQL = "SELECT * FROM Tasks"
intI = 0
Set rsTasks = dbsTest.OpenRecordset(strSQL, dbOpenDynaset)
With rsTasks
Do Until .EOF
If intI < 6 Then
strChkName = chkList(intI)
strLblName = lblList(intI)

Me.Controls(strChkName).Visible = True
Me.Controls(strLblName).Visible = True
Me.Controls(strChkName).Value = .Fields("ID").Value
Me.Controls(strLblName).Caption = .Fields("TASK_NAME").Value
intI = intI + 1
End If
.MoveNext
Loop
End With
rsTasks.Close
Set rsTasks = Nothing

Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description

End Sub
===========================================

Hope this helps. If you have any other questions or concerns, please feel
free to let me know. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
R

Rockn

That was awesome!! Thanks for the info, it is greatly appreciated.


"Charles Wang [MSFT]" said:
Hi Rockn,
You can save your checkboxes names and labels names into two arrays. Then
you can dynamic set the attributes according to the record loop and the
array index.
For example:
===================================
Public chkList As Variant
Public lblList As Variant


Private Sub cmdLoad_Click()
Dim dbsTest As DAO.Database
Dim rsTasks As DAO.Recordset
Dim strSQL As String
Dim strChkName As String
Dim strLblName As String
Dim intI As Integer

chkList = Array("chk0", "chk1", "chk2", "chk3", "chk4", "chk5")
lblList = Array("lbl0", "lbl1", "lbl2", "lbl3", "lbl4", "lbl5")

On Error GoTo ErrorHandler

Set dbsTest = CurrentDb
strSQL = "SELECT * FROM Tasks"
intI = 0
Set rsTasks = dbsTest.OpenRecordset(strSQL, dbOpenDynaset)
With rsTasks
Do Until .EOF
If intI < 6 Then
strChkName = chkList(intI)
strLblName = lblList(intI)

Me.Controls(strChkName).Visible = True
Me.Controls(strLblName).Visible = True
Me.Controls(strChkName).Value = .Fields("ID").Value
Me.Controls(strLblName).Caption = .Fields("TASK_NAME").Value
intI = intI + 1
End If
.MoveNext
Loop
End With
rsTasks.Close
Set rsTasks = Nothing

Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description

End Sub
===========================================

Hope this helps. If you have any other questions or concerns, please feel
free to let me know. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
=========================================================
 
C

Charles Wang [MSFT]

Hi Rockn,
Thank you for your response.

I am glad to hear that the suggestions are helpful. If you have any other
questions or concerns, please feel free to let me know.

Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top