If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Many Checkbox(s) to one text box?
Hello again,
I have a form to which I have 4-5 checkbox questions. How do I have the checkboxes, if checked, displays the results in a bound textbox? For example: x is the check x 1.Maintain tires _ 2.Check oil x 3.Fill up with gas _ 4.Paint car In my textbox, I need this to be displayed: Maintain tires, fill up with gas Even better would be to have, for the first checkbox x 1.Maintian tires at_____ (where a user can enter a number) then the whole line appear int he text box. Eg. Maintain tires at 55ppi Any ideas? Thanks a million! |
#2
|
|||
|
|||
Many Checkbox(s) to one text box?
Slagg,
This problem is much like building an SQL search string for filtering a query or report. Loop through the controls, building the string as you go. You could use a naming convention to refer to the text labels, or place the text in the Tag property of the checkbox itself to get the associated text. Sub AssignTextBox() Dim ctl as Control Dim strWS as String ' Working String strWS = "" For Each ctl in Me.Controls If ctl.ControlType = acCheckBox Then strWS = strWS & ctl.Tag & ", " End If Next ctl ' Strip comma and space from the end of the string strWS = Left (strWS, Len(strWS)-2) ' Assign to textbox Me![YourTextbox] = strWS End Sub Then call the subroutine in the AfterUpdate event of each checkbox: Call AssignTextbox To handle the more complicated version, handle each case separately, using another string variable to hold the string to add for each particular case: Dim strCaseString as String For Each ctl in Me.Controls Select Case ctl.Name Case "chkMaintainTires" If IsNull(Me![txtTirePressure]) Then strCaseString = ctl.Tag Else strCaseString = ctl.Tag & " at " & Me![txtTirePressure] & " psi" End If .... other cases End Select strWS = strWS & strCaseString & ", " Next ctl Hope that helps. Sprinks " wrote: Hello again, I have a form to which I have 4-5 checkbox questions. How do I have the checkboxes, if checked, displays the results in a bound textbox? For example: x is the check x 1.Maintain tires _ 2.Check oil x 3.Fill up with gas _ 4.Paint car In my textbox, I need this to be displayed: Maintain tires, fill up with gas Even better would be to have, for the first checkbox x 1.Maintian tires at_____ (where a user can enter a number) then the whole line appear int he text box. Eg. Maintain tires at 55ppi Any ideas? Thanks a million! |
Thread Tools | |
Display Modes | |
|
|