Multi-Column ListBox

ErickMJ

Registered User.
Local time
Today, 05:28
Joined
Aug 6, 2012
Messages
18
I have an Access Database with a multi-column list box, and I want to hide certain columns based on if certain checkboxes are checked or not. As it stands, I can use code like

If ChkClient = 0 Then
Me.lstDisplayReport.ColumnWidths = "0; 1 in; 0; 1in ; 1 in; 1in; 1 in"
Else
Me.lstDisplayReport.ColumnWidths = "0; 1in ; 1in ; 1 in; 1 in; 1 in; 1 in"
End If

to hide a single column or group of columns at a time. The problem is that I can't say, have a checkbox for one field and another for a different field; even having this code for two separate columns causes it to fail. Is there a way to make criteria to hide multiple columns based on checkboxes?
 
Hi could you rephrase the problem you have again, I am not getting the last part of your problem.

to hide a single column or group of columns at a time. The problem is that I can't say, have a checkbox for one field and another for a different field; even having this code for two separate columns causes it to fail. Is there a way to make criteria to hide multiple columns based on checkboxes?
 
You can put all your check boxes in one frame, and have the list columsn hide or show on_click event of that frame by checking which checkboxes have been marked.

An event smarter way would be to label your checkboxes as chk1, chk2, chk3 and have a loop to check as below:

Code:
Dim i as integer, NoOfChks as integer, strWidths as string
NoOfChks = 6
For i = 1 to NoOfChks
  if Me.Controls("chk" & i) = -1 then
    strWidths = strWidths & "1in; "
  else
    strWidths = strWidths & "0in; "
  end if
Next i
Me.lstDisplayReport.ColumnWidths = strWidths
 
Another question on a similar vein. Let's say I have one column, the first, which should always be =0in. How do I get the string to start on column 2?
 
You just have to initialize your strWidths

Code:
Dim i as integer, NoOfChks as integer, strWidths as string
NoOfChks = 6
strWidths = "0in; "
For i = 1 to NoOfChks
  if Me.Controls("chk" & i) = -1 then
    strWidths = strWidths & "1in; "
  else
    strWidths = strWidths & "0in; "
  end if
Next i
Me.lstDisplayReport.ColumnWidths = strWidths
 

Users who are viewing this thread

Back
Top Bottom