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

change property of listbox on application level

Status
Not open for further replies.
Mar 27, 2002
168
NL
I have a main form with 3 listboxes
sometimes its handy to have the multiselect property single (code 1) and sometimes its better to have multiselect none (code 0).
I'll make a checkbox with code
Private Sub selEnkelvoudig_Click()
If selEnkelvoudig = False Then
Forms("frmHoofdFormulier").Controls("Staallijst").MultiSelect = 0
Forms("frmHoofdFormulier").Controls("Aanvraaglijst").MultiSelect = 0
Forms("frmHoofdFormulier").Controls("Uitleenlijst").MultiSelect = 0
Else
Forms("frmHoofdFormulier").Controls("Staallijst").MultiSelect = 1
Forms("frmHoofdFormulier").Controls("Aanvraaglijst").MultiSelect = 1
Forms("frmHoofdFormulier").Controls("Uitleenlijst").MultiSelect = 1
End If
End Sub
I get follow error:
not possible to set value on this object,
anybody knows how this works?
thanx
Gerard
 
Try

Private Sub selEnkelvoudig_Click()

If selEnkelvoudig = False Then
Form_frmHoofdFormulier.Staallijst.MultiSelect = 0
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 0
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 0
Else
Form_frmHoofdFormulier.Staallijst.MultiSelect = 1
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 1
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 1
End If
End Sub

instead. Long shot but you never know.

Cheers,

Pete
 
thanx for the shot but error 2448 is coming up
same error as before,

do u have another try for me?
Thnx in advance,

gerard
P.S. it's not possible to change this property in the easy way, it's only changed in the design view usually, so there must a way to go around this
 
Does the code not work at all?

Because you may have to make sure that nothing is selected in the listbox before you click the checkbox. So add to the code above some code that will go through the listbox and deselect anything that's selected.

Private Sub selEnkelvoudig_Click()

Dim varItem As variant, ctl1 As control, ctl2 As control, ctl3 As control

Set ctl1 = Form_frmHoofdFormulier.Staallijst
Set ctl2 = Form_frmHoofdFormulier.Aanvraaglijst
Set ctl3 = Form_frmHoofdFormulier.Uitleenlijst

For Each varItem in ctl1.ItemsSelected
ctl.Selected(varItem) = False
Next varItem

For Each varItem in ctl2.ItemsSelected
ctl.Selected(varItem) = False
Next varItem

For Each varItem in ctl3.ItemsSelected
ctl.Selected(varItem) = False
Next varItem

If selEnkelvoudig = False Then
Form_frmHoofdFormulier.Staallijst.MultiSelect = 0
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 0
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 0
Else
Form_frmHoofdFormulier.Staallijst.MultiSelect = 1
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 1
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 1
End If
End Sub

See if that helps,

Cheers,

Pete
 
It's a clear story,
Thnx for the easy method to deselect values ;)
but it doesn't fix the problem.
I think, we have to go around the normal way,
in the help file from VBA stands that the property only can be changed in design view
I can't believe that but normally it give more problems than properties which can change.

do U have more ideas?
Thnx in advance,
Gerard
 
Hmmmmmm, you can try turning echo off, open the form in design view, change the property by code then reopen in normal view.

I've never successfully dones this since I seem to get errors when I try it but here's some code that you could try

Private Sub selEnkelvoudig_Click()

DoCmd.Echo False
DoCmd.Close
DoCmd.OpenForm "frmHoofdFormulier", acDesign, , , , acHidden

If selEnkelvoudig = False Then
Form_frmHoofdFormulier.Staallijst.MultiSelect = 0
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 0
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 0
Else
Form_frmHoofdFormulier.Staallijst.MultiSelect = 1
Form_frmHoofdFormulier.Aanvraaglijst.MultiSelect = 1
Form_frmHoofdFormulier.Uitleenlijst.MultiSelect = 1
End If

Docmd.close
Docmd.OpenForm "frmHoofdFormulier"
Docmd.echo True
Me.refresh
Me.requery
End Sub

Hope that helps,

Cheers,

Pete

 
Hi Pete,

have to change something to ur code but now it works.
I don't know how it beholds when I make a MDE file but can check,
thnx u help me out, but I'm carefully with it, it's very complex operation for very easy handling. Don't know if I like this,
;-)

Greetz,
gerard
 
What did you change? I don't use this because it tends to crash my database but that might just be me.

Did you change anything important?

Cheers,

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top