checkbox label

T

Terry

Hello
Is there anyway to pick up the value of a checkbox label?
EX:
When I created the checkboxes, they came with a label (which I added a
caption to).
Now I would like to pickup that caption for that checkbox's label.

ActiveControl.label.caption ---- in essence. As you know, this does not
work.

Thank you so much
Terry V
 
A

Allen Browne

The attached label is the first member of the control's Controls collection,
so its Caption would be:
[MyCheckbox].Controls(0).Caption
 
F

fredg

Hello
Is there anyway to pick up the value of a checkbox label?
EX:
When I created the checkboxes, they came with a label (which I added a
caption to).
Now I would like to pickup that caption for that checkbox's label.

ActiveControl.label.caption ---- in essence. As you know, this does not
work.

Thank you so much
Terry V
I don't know what you mean by 'pick up the value of a checkbox label'?

You can change a label's caption:
LabelName.Caption = "This is new."

You can read a label's caption:
Dim strX as String
strX = [LabelName].Caption

Are either of these what you want?
 
T

Terry

If Im understanding correctly;
If I want the caption of the activecontrol (when a checkbox is clicked) then
I could use:

var = Form.ActiveControl.Controls(0).Caption

Is this correct?

Thank you :)
Terry V

Allen Browne said:
The attached label is the first member of the control's Controls collection,
so its Caption would be:
[MyCheckbox].Controls(0).Caption

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Terry said:
Is there anyway to pick up the value of a checkbox label?
EX:
When I created the checkboxes, they came with a label (which I added a
caption to).
Now I would like to pickup that caption for that checkbox's label.

ActiveControl.label.caption ---- in essence. As you know, this does not
work.
 
T

Terry

By pickup, I mean get the caption of the activecontrol into a variable....
sorry for the confusion.

Thank you
Terry V
fredg said:
Hello
Is there anyway to pick up the value of a checkbox label?
EX:
When I created the checkboxes, they came with a label (which I added a
caption to).
Now I would like to pickup that caption for that checkbox's label.

ActiveControl.label.caption ---- in essence. As you know, this does not
work.

Thank you so much
Terry V
I don't know what you mean by 'pick up the value of a checkbox label'?

You can change a label's caption:
LabelName.Caption = "This is new."

You can read a label's caption:
Dim strX as String
strX = [LabelName].Caption

Are either of these what you want?
 
A

Allen Browne

If the active control has an attached label, it would be:
Screen.ActiveControl.Controls(0).Caption

However, I've always found that syntax to be rather error-prone, so make
sure you have error handling in your code.
 
Joined
May 10, 2011
Messages
4
Reaction score
0
Is there a way to take the checkbox label name and export it to excel using transferspreadsheet method? basically what i want to do it export the checkbox values if they exist to spreadsheet and print the label name in the first row of the spreadsheet. Currently i have 50 different checkboxes and it exports to excel only if there is a value for each checkbox on to different tabs in one spreadsheet. Only part i am hanging up on is how to export the label name of the checkbox onto the first of each tab. anyway to do that?

here is my code

Code:
For Each ctl In MyForm.Controls
    Select Case ctl.ControlType
    Case acCheckBox
        If ctl = True Then
            Set rst = db.OpenRecordset(ctl.Name)
            If Not rst.EOF Then
                DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, ctl.Name, fileIn, True, ""
            End If
            rst.Close
            Set rst = Nothing
        End If
    End Select
Next ctl
strFileName = Dir("C:\temp\Records.xls")
If strFileName = "Records.xls" Then
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Open(strFileName)
    
    intCountofSheets = xlBook.sheets.Count
    intCurrentSheet = 1
    Do While intCurrentSheet <= intCountofSheets
    xlBook.Worksheets(intCurrentSheet).Activate
        With xlApp.ActiveSheet.UsedRange
            .Font.Name = "Tahoma"
            .Font.Size = 10
....
 

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