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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Design Ideas

Status
Not open for further replies.

Kherozen

Programmer
Jun 5, 2003
129
CA
Hi,
I want to create checkbox beside textbox so that if the checkbox is checked then the textbox will appears as a column in a datasheet(ie if the Project Checkbox is checked, I want the column "Project" to appear). I got everything ok but ... since I got a hundred of textbox how can I avoid coding something like that
stOpenArgs

if Me!chkField1 then
stOpenArgs = stOpenArgs & Field1
if Me!chkField2 then ....
...
...
...
if chkField200 then ...
 
There's a cleaner solution (maybe slower but the code is faster to write. Just Name the checkbox chkTextBoxName

and put the code :
Code:
Dim stOpenArgs As String
Dim myControl As Control
Dim Delim As String
Delim = "#"
For Each myControl In Me.Controls
    Select Case myControl.ControlType
        Case acCheckBox
            If InStr(myControl.Name, "chk") And myControl.Value = True Then
                stOpenArgs = stOpenArgs & Mid(myControl.Name, 4) & Delim
                MsgBox stOpenArgs
            End If
    End Select
Next
and in the openform
Code:
Dim stOpenArgs As String
Dim Delim As String
Delim = "#"

If Not IsNull(Me.OpenArgs) Then
    stOpenArgs = Me.OpenArgs
    
     Dim Args(40) As String
     Dim ArgumentNumber As Integer
     ArgumentNumber = 0
    
     Dim position
     While Len(stOpenArgs)
         position = InStr(stOpenArgs, Delim)
         If position = 0 Then
             Args(ArgumentNumber) = stOpenArgs
             stOpenArgs = ""
         Else
             Args(ArgumentNumber) = Left(stOpenArgs, position - 1)
             stOpenArgs = Right(stOpenArgs, Len(stOpenArgs) - position)
             ArgumentNumber = ArgumentNumber + 1
         End If
     Wend
End If

Dim cpt As Integer
For cpt = 0 To ArgumentNumber - 1
    Me.Controls(Args(cpt)).ColumnHidden = False
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top