Listbox to Table Field

M

MSU Sptn

I have a multiselect listbox (lstProgramManagers) in the form
'Frm_ProgramManagers' where emails can be selected. The list box row source
is defined as

SELECT [TblProgramManager].[PM_ID], [TblProgramManager].[T_Manager_Email]
FROM TblProgramManager;

I need to have the selected emails be placed in the field
'T_Reminder_Mailing_List' on the table 'TblCompliance' in a list separated by
a semicolon so the SendObject command can grab the list of addresses. The
selected emails need to be saved in the table until changes are made to the
listbox selection. The selected emails may be different for each recordset
in 'TblCompliance' so I also need to apply a filter. I am new to VB code and
am trying to fudge my way through it, is there a way to save selected items
from a list box to the corresponding row in a table?
 
S

Scott McDaniel

You must iterate the ItemsSelected collection:

Dim var As Variant
Dim strEmails As String

For each Var in Me.YourListbox.ItemsSelected
strEmails = strEmails & ";" & Me.YourListBox(0,var)
Next var

Currentdb.Execute "UPDATE YourTable SET strEmails='" & strEmails & "' WHERE
YourID=" & ME!YourIdField
 
M

MSU Sptn

Thank you! I am getting closer. I used the code below, but I get an error
saying "Could not find the file 'C:\My Documents\TblCompliance.mdb'" What am
I doing wrong?
-----------------
For Each var In Me.lstProgram_Manager.ItemsSelected
strEmails = strEmails & ";" & Me.lstProgram_Manager.Column(0, var)
Next var

CurrentDb.Execute "UPDATE TblCompliance.T_Reminder_Mailing_List SET
strEmails='" & strEmails & "' WHERE AN_AutoNumber = " & Me!txtAN_AutoNumber




Scott McDaniel said:
You must iterate the ItemsSelected collection:

Dim var As Variant
Dim strEmails As String

For each Var in Me.YourListbox.ItemsSelected
strEmails = strEmails & ";" & Me.YourListBox(0,var)
Next var

Currentdb.Execute "UPDATE YourTable SET strEmails='" & strEmails & "' WHERE
YourID=" & ME!YourIdField

MSU Sptn said:
I have a multiselect listbox (lstProgramManagers) in the form
'Frm_ProgramManagers' where emails can be selected. The list box row
source
is defined as

SELECT [TblProgramManager].[PM_ID], [TblProgramManager].[T_Manager_Email]
FROM TblProgramManager;

I need to have the selected emails be placed in the field
'T_Reminder_Mailing_List' on the table 'TblCompliance' in a list separated
by
a semicolon so the SendObject command can grab the list of addresses. The
selected emails need to be saved in the table until changes are made to
the
listbox selection. The selected emails may be different for each
recordset
in 'TblCompliance' so I also need to apply a filter. I am new to VB code
and
am trying to fudge my way through it, is there a way to save selected
items
from a list box to the corresponding row in a table?
 
M

MSU Sptn

Ok, now it works, I made some edits as follows:
--------
For Each var In Me.lstProgram_Manager.ItemsSelected
strEmails = strEmails & Me.lstProgram_Manager.Column(1, var) & ";"
Next var

CurrentDb.Execute "UPDATE TblCompliance SET T_Reminder_Mailing_List='" &
strEmails & "' WHERE AN_AutoNumber = " & Me!txtAN_AutoNumber
-----------
Now the nightmares can stop, thank you very much!


Scott McDaniel said:
You must iterate the ItemsSelected collection:

Dim var As Variant
Dim strEmails As String

For each Var in Me.YourListbox.ItemsSelected
strEmails = strEmails & ";" & Me.YourListBox(0,var)
Next var

Currentdb.Execute "UPDATE YourTable SET strEmails='" & strEmails & "' WHERE
YourID=" & ME!YourIdField

MSU Sptn said:
I have a multiselect listbox (lstProgramManagers) in the form
'Frm_ProgramManagers' where emails can be selected. The list box row
source
is defined as

SELECT [TblProgramManager].[PM_ID], [TblProgramManager].[T_Manager_Email]
FROM TblProgramManager;

I need to have the selected emails be placed in the field
'T_Reminder_Mailing_List' on the table 'TblCompliance' in a list separated
by
a semicolon so the SendObject command can grab the list of addresses. The
selected emails need to be saved in the table until changes are made to
the
listbox selection. The selected emails may be different for each
recordset
in 'TblCompliance' so I also need to apply a filter. I am new to VB code
and
am trying to fudge my way through it, is there a way to save selected
items
from a list box to the corresponding row in a table?
 

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