List box selections not visible

G

Guest

My first attempt to post the question was muddy at best, my apologies,
hopefully this will be clearer. Any assistance is greatly appreciated!!!
I have created a multi select list box (on my main input form) and created
an update button that dumps the selections into a table (John Vinson code,
thanks very much!). The problem is that after I close the form and navigate
back to the record the selections are not visible in the list box and I will
need to have to come back to update the list often, what did I miss that
wipes out the selections in the list box? (records update perfectly to
table) also, I do not know what this line of code was supposed to do (from JV
code):

Me.subAnimalCondition.Requery (was this a subform?)

Johns full code listed below:
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,
' newly 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 currently
' 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
 
G

Guest

The values selected in a list box are not presistent. When you close the
form, it has no way of remembering what items were selected. You did not
miss anything, this is normal behaviour.

The line of code you asked about appears to be a subform requery.
 
G

Guest

Thank you so much, now I won't be beating my head against a wall for nothing,
I will just figure out a different way to show the updates. Appreciate it!

Klatuu said:
The values selected in a list box are not presistent. When you close the
form, it has no way of remembering what items were selected. You did not
miss anything, this is normal behaviour.

The line of code you asked about appears to be a subform requery.

Ann said:
My first attempt to post the question was muddy at best, my apologies,
hopefully this will be clearer. Any assistance is greatly appreciated!!!
I have created a multi select list box (on my main input form) and created
an update button that dumps the selections into a table (John Vinson code,
thanks very much!). The problem is that after I close the form and navigate
back to the record the selections are not visible in the list box and I will
need to have to come back to update the list often, what did I miss that
wipes out the selections in the list box? (records update perfectly to
table) also, I do not know what this line of code was supposed to do (from JV
code):

Me.subAnimalCondition.Requery (was this a subform?)

Johns full code listed below:
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,
' newly 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 currently
' 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
 
B

BrianH

Hi I have been trying to create a multi-select list box for a while now
with no success. Is there anyway I can do this without code since I am
not too familiar with it. I would like to create a listbox like the
ones for the form wizards just with my data. THe first box would be my
tables (which I can do so far) then I need to select one of the tables
and in the second box I need their fields to show up and then I would
like to select which ever fields I need from their to put into a query.

Any help?

THanks in advance!

~Brian
 

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