Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Construct a string from "Yes" check box fields?

Status
Not open for further replies.

gusbrunston

Programmer
Feb 27, 2001
1,234
US
I am designing a report listing available rental properties for the use of real estate broker's representatives. The report should include information about 50 yes/no fields that enumerate amenties, such as "Air Conditioned, Attic Fan, Disposer, Dryer, Fenced Yard, etc."

So far, I can list all 50 check boxes with labels on the report and there they do properly display the check mark or absence thereof.

But, that takes up a lot of vertical space, and increases the size of the report from maybe 3 to 6 or more pages.

How, please, can I construct a string from NAMES or CAPTIONS or LABELS of only those boxes that are checked?

So that, there would be a string, e.g., "Attic Fan, Dishwasher, Disposer, Dryer, Eating Space, Pool, Refrigerator, Skylights, Vaulted Ceilings, Washer, Water Paid, Window Coverings" if those were the checked boxes.

If you'd like a better picture of what I'm talking about, I could email or fax a page of the report...

I've done a lot of work on forms, and now I'm starting on the reports.

Many thanks,

:cool:

Gus Brunston
An old PICKer
padregus@home.com
 
w/o details, I'm just doing an 'ad-hoc' thing here ...

Private Function Chk2Str() As String

[tab]dim strTemp as String

[tab]If (Me.chkAC) then
[tab][tab]If (Len(strTemp) > 0) then
[tab][tab][tab]strTemp = strTemp & ", "
[tab][tab]End If
[tab][tab]strTemp = strTemp & "Air Conditioned"
[tab]End If

[tab]'repeat for each item

[tab]Chk2Str = strTemp

End Function

The alternative depends A LOT on your diccipline. is below.

It NEEDs you to NOT have any other check boxes on the form (or some other logic to identify the controls of interest) AND you CAREFUL Naming of the checkmoxes.

Code:
Public Function basChk2Str() As String

    With Forms!frmRealEstate
        For MyCtrl = 0 To .Controls.Count - 1
            If (.Controls(MyCtrl).ControlType = acCheckBox) Then
                If (.Controls(MyCtrl)) Then
                    If (Len(strTemp) <> 0) Then
                        strTemp = strTemp & &quot;, &quot;
                    End If
                    strTemp = strTemp & right(.Controls(MyCtrl).Name, Len(.Controls(MyCtrl).Name) - 3)
                End If
            End If
        Next MyCtrl
    End With

    basChk2Str = strTemp

End Function

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Dear Michael,
Thank you so much for the time you gave this. I'm going to print it out so that I can give it the study it deserves (I have a little trouble with the blue background on tek-tips).
Thanks again, and I'll post what I'm able to do back here.
:) Gus Brunston
An old PICKer
padregus@home.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top