Hi,
I use the following code to implement a multi select list box. I tried to modified it (by using a loop) so that the user cannot select more than 5 items in the list box and probably to take a message the limit of selections is reached.
Any help?
Private Sub List15_AfterUpdate()
Dim rst As Recordset
Dim varItem As Variant
'--- empty temp table in preparation to receive new requests
CurrentDb.Execute ("DELETE * from _temp;")
'--- open the _temp table
Set rst = CurrentDb.OpenRecordset("_temp")
'--- loop through all selected clients in the list box
' adding their names to the _temp table
For Each varItem In List15.ItemsSelected
rst.AddNew
rst!client = List15.ItemData(varItem)
rst.Update
Next varItem
'--- close the table
rst.Close
Set rst = Nothing
'--- refresh the form or could put a docmd to run a report, open a form, etc
Me.Refresh
End Sub
I use the following code to implement a multi select list box. I tried to modified it (by using a loop) so that the user cannot select more than 5 items in the list box and probably to take a message the limit of selections is reached.
Any help?
Private Sub List15_AfterUpdate()
Dim rst As Recordset
Dim varItem As Variant
'--- empty temp table in preparation to receive new requests
CurrentDb.Execute ("DELETE * from _temp;")
'--- open the _temp table
Set rst = CurrentDb.OpenRecordset("_temp")
'--- loop through all selected clients in the list box
' adding their names to the _temp table
For Each varItem In List15.ItemsSelected
rst.AddNew
rst!client = List15.ItemData(varItem)
rst.Update
Next varItem
'--- close the table
rst.Close
Set rst = Nothing
'--- refresh the form or could put a docmd to run a report, open a form, etc
Me.Refresh
End Sub