Multi Select List box

F

FrankC

I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList", dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm
 
D

Dirk Goldgar

FrankC said:
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not
when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList",
dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm


That seems strange. What event are you using to run this code?
 
D

Dirk Goldgar

FrankC said:
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not
when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList",
dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm


That seems strange. What event are you using to run this code?
 
F

FrankC

Dale,
I have the standard error handling in the code.
Put in the Debug.print statements and with 'extended' it prints only the one
before the For loop.

Frank

Dale_Fye via AccessMonster.com said:
Do you have an error handler configured for this code segment? If not, add
one. It sounds like you might be generating an error. Also, you might want
to add a line right after the For loop begins, something like:

debug.print varItm

Might even want to add one before the loop:
debug.print ctl.name, ctl.ItemsSelected.count

HTH
Dale
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList", dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm
 
F

FrankC

Dale,
I have the standard error handling in the code.
Put in the Debug.print statements and with 'extended' it prints only the one
before the For loop.

Frank

Dale_Fye via AccessMonster.com said:
Do you have an error handler configured for this code segment? If not, add
one. It sounds like you might be generating an error. Also, you might want
to add a line right after the For loop begins, something like:

debug.print varItm

Might even want to add one before the loop:
debug.print ctl.name, ctl.ItemsSelected.count

HTH
Dale
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList", dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm
 
F

FrankC

Dirk,
The code runs on a OnClick event for a command button on the form. I also
tried it on the Lost Focus event for the list box. Same result.
Frank

Dirk Goldgar said:
FrankC said:
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not
when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList",
dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm


That seems strange. What event are you using to run this code?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
F

FrankC

Dirk,
The code runs on a OnClick event for a command button on the form. I also
tried it on the Lost Focus event for the list box. Same result.
Frank

Dirk Goldgar said:
FrankC said:
I have a list box using multi select that appends the selected items to a
table ‘HoldProsList’.
The form is ‘fSelectPCPlan’ and the control is ‘SelectPC’ and the bound
column is an integer.
It works fine when the Multi Select property is set to ‘Simple’ but not
when
it is ‘Extended’.
The flow jumps to the end after the ‘For each…. ‘ statement. (No errors)

The code is:
' Copy the ProspectID's into the HoldProsList table
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant
Set rs = DBEngine(0)(0).OpenRecordset("HoldProsList",
dbOpenDynaset,
dbAppendOnly)
Set frm = Forms![fSelectPCPlan]
Set ctl = frm!SelectPC
For Each varItm In ctl.ItemsSelected
rs.AddNew
rs![ProspectID] = Me.SelectPC.ItemData(varItm)
rs.Update
Next varItm


That seems strange. What event are you using to run this code?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

FrankC said:
Dale,
I have the standard error handling in the code.
Put in the Debug.print statements and with 'extended' it prints only the
one
before the For loop.


What did that Debug.Print statement say was the value of
ctl.ItemsSelected.Count? I can't reproduce your problem here, using Access
2003. Have you said yet what version of Access you're using?
 
D

Dirk Goldgar

FrankC said:
Dale,
I have the standard error handling in the code.
Put in the Debug.print statements and with 'extended' it prints only the
one
before the For loop.


What did that Debug.Print statement say was the value of
ctl.ItemsSelected.Count? I can't reproduce your problem here, using Access
2003. Have you said yet what version of Access you're using?
 
F

FrankC

Dirk and Dale,

Problem solved!

In the sub, before the section we have been dealing with, there was a
Me.Refresh line. In Extended mode the refresh resets the list box and set
the selections to null. It doesn't do this in Simple mode. I moved the
refresh to later in the procedure and everything works fine. I tried it
with both the every-line and the only-selected lines versions and it works
now in both cases. The help item for Multi Select says this should happen
when you requery the list box but doesn't say anything about refreshing the
form.

Thanks for you quick responses and help.
Frank
 
F

FrankC

Dirk and Dale,

Problem solved!

In the sub, before the section we have been dealing with, there was a
Me.Refresh line. In Extended mode the refresh resets the list box and set
the selections to null. It doesn't do this in Simple mode. I moved the
refresh to later in the procedure and everything works fine. I tried it
with both the every-line and the only-selected lines versions and it works
now in both cases. The help item for Multi Select says this should happen
when you requery the list box but doesn't say anything about refreshing the
form.

Thanks for you quick responses and help.
Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top