Mutiple Selection being saved to table from listbox

J

Jason

I am using a Listbox and allowed Multiple selection to be achieved. The
problem is that the data is not being stored in the table. I am having an
hard time trying to figure out how to get the table to populate with mutliple
choices. Can somsone please advice or help with the coding that is needed.
 
J

John W. Vinson

I am using a Listbox and allowed Multiple selection to be achieved. The
problem is that the data is not being stored in the table. I am having an
hard time trying to figure out how to get the table to populate with mutliple
choices. Can somsone please advice or help with the coding that is needed.

It's more work than you might think! Here's some sample code from my animal
shelter database:

Private Sub cmdProcess_Click()
' Comments : Update the AnimalCondition table based on the selections in
' the unbound multiselect listbox lstHealthIssues.
' Newly selected rows will be added to the table, cleared
' rows will be deleted.
' Parameters: None
' Modified : 01/29/02 by JWV
'
' --------------------------------------------------
' Populate the AnimalCondition table with the selected issues
On Error GoTo PROC_ERR

Dim iItem As Integer
Dim lngCondition As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset

' save the current record if it's not saved
If Me.Dirty = True Then
Me.Dirty = False
End If
Set db = CurrentDb
' Open a Recordset based on the table
Set rs = db.OpenRecordset("AnimalCondition", dbOpenDynaset)
With Me!lstHealthIssues
' Loop through all rows in the Listbox
For iItem = 0 To .ListCount - 1
lngCondition = .Column(0, iItem)
' Determine whether this AnimalID-HealthID combination is
' in the table
rs.FindFirst "[AnimalID] = " & Me.AnimalID & " AND " _
& "[HealthIssueID] = " & lngCondition
If rs.NoMatch Then ' this item has not been added
If .Selected(iItem) Then
' add it
rs.AddNew
rs!AnimalID = Me.AnimalID
rs!HealthIssueID = lngCondition
rs.Update
End If ' if it wasn't selected, ignore it
Else
If Not .Selected(iItem) Then
' delete this record if it's been deselected
rs.Delete
End If ' if it was selected, leave it alone
End If
Next iItem
End With
rs.Close
Set rs = Nothing
Set db = Nothing
Me.subAnimalCondition.Requery

PROC_EXIT:
Exit Sub

PROC_ERR:
MsgBox "Error " & Err.Number & " in cmdProcess_Click:" _
& vbCrLf & Err.Description
Resume PROC_EXIT

End Sub
 
M

Mark Han[MSFT]

Dear Customer,

Thank you for using Microsoft MSDN Managed Newsgroup. My name is Mark Han.
I am glad to work with you on this issue.

From your description, I understand that you would like to use standard
multiple-selection list to support multiple selection
If I have misunderstood, please let me know.

After reviewing the log history, I found John has sent you a detail
example. Thank you, John. For your convenience, I do some additional
research, there is an article to share with
you:http://msdn.microsoft.com/en-us/library/aa511484.aspx#multipleSelectionL
ists

Hope the above helpful.

If there is anything unclear, please do not hesitate to let me know.

I look forward to your update.

Best regards,
Mark Han
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or
a Microsoft Support Engineer within 2 business day is acceptable. Please
note that each follow up response may take approximately
2 business days as the support professional working with you may need
further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are
best handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx

============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
M

Mark Han[MSFT]

Dear Customer,

How are you? I haven't heard from you for a few days.

I am concerned if the explanation I sent was not clear enough. If that's
the case, please tell me directly. I will go through the detail with you
and ensure it is easy for you to follow.

Besides, I understand that you might have a busy schedule and it is
convenient to you to send me a note to tell me the status of the case.

If you have any questions or concerns on the above, please email me.

I look forward to hearing from you.

Thanks.
Best regards,
Mark Han
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
J

John W. Vinson

Dear Customer,

How are you? I haven't heard from you for a few days.

I am concerned if the explanation I sent was not clear enough. If that's
the case, please tell me directly. I will go through the detail with you
and ensure it is easy for you to follow.

Besides, I understand that you might have a busy schedule and it is
convenient to you to send me a note to tell me the status of the case.

If you have any questions or concerns on the above, please email me.

I look forward to hearing from you.

Are you addressing me, Mark, or the OP? I wasn't aware that support services
considered the public m.p.a.forms group a managed group - but we'll be happy
to see you here more often!
 
M

Mark Han[MSFT]

Hi John,

Thank you for the update.

in order to address your concern, I would like to explain the following
when I accepted the post, I found that you have sent a detail sample to the
Jason. I appreciate your time and efforts. So then I did some additional
research and share an related article .
List
Boxes:http://msdn.microsoft.com/en-us/library/aa511484.aspx#multipleSelectio
nLists.

Since I have not heard from Jason for a few days, I wrote to follow up the
issue to check if Joson still has the concern on that. if so, I would like
to work with him on the issue. it might be that I didn't directly reply to
Jason confused you. Sorry for the inconvenience.

Besides, I understand that you would like me be more ofter here. what I do
is to follow up per post based on our process and reply to our customer in
manner time. I appreciate your understanding. if you have any other
concerns, we welcome you post here.

Have a nice day.

Best regards,
Mark Han
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 

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