List box question

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I'm using an unbound listbox as a record selector for a form which works
fine. The problem is that there are other ways for the user to move from
record to record in the form. How can I make the listbox's selected item
follow the current record in the form without binding it to the forms record
source?
 
Hi:

You could use the Form Filter property to filter for a specific record. If
ListBox is unbound trap the "AfterUpdate" event of ListBox with some code
like this

Me.Filter = "[CustomerName] = '" & Me.List0.Value & "'"
Me.FilterOn = True

This assumes you are filtering on a CustomerName field wth the value from
ListBox.

You can turn "AllowAdditions" and "AllowDeletions" to form to false.

Regards,

Naresh Nichani
Microsoft Access MVP
 
Thanks for the reply.
I'm not sure I made the problem as clear as I should have. The form is
steered to the record selected in the listbox with this code:

Private Sub SelectorListBox_AfterUpdate()
' Find the record that matches the control.
If Me!SelectorListBox <> "#Deleted" Then
Me.RecordsetClone.FindFirst "[ApplicationID] = " &
Me![SelectorListBox]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This works fine for this purpose. The problem is that if the user moves to
another record in the form, the highlited 'selected item' in the listbox
does not follow the position of the form in the recordset. In other words,
I have the form following the selection in the listbox but I need the
selected item in the listbox to also follow the form as it moves to other
records. It is confusing when the selection in the listbox stays put, but
the form has moved to another record.

Naresh Nichani MVP said:
Hi:

You could use the Form Filter property to filter for a specific record. If
ListBox is unbound trap the "AfterUpdate" event of ListBox with some code
like this

Me.Filter = "[CustomerName] = '" & Me.List0.Value & "'"
Me.FilterOn = True

This assumes you are filtering on a CustomerName field wth the value from
ListBox.

You can turn "AllowAdditions" and "AllowDeletions" to form to false.

Regards,

Naresh Nichani
Microsoft Access MVP


Jerry said:
I'm using an unbound listbox as a record selector for a form which works
fine. The problem is that there are other ways for the user to move from
record to record in the form. How can I make the listbox's selected item
follow the current record in the form without binding it to the forms record
source?
 
Jerry said:
Thanks for the reply.
I'm not sure I made the problem as clear as I should have. The form is
steered to the record selected in the listbox with this code:

Private Sub SelectorListBox_AfterUpdate()
' Find the record that matches the control.
If Me!SelectorListBox <> "#Deleted" Then
Me.RecordsetClone.FindFirst "[ApplicationID] = " &
Me![SelectorListBox]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This works fine for this purpose. The problem is that if the user moves to
another record in the form, the highlited 'selected item' in the listbox
does not follow the position of the form in the recordset. In other words,
I have the form following the selection in the listbox but I need the
selected item in the listbox to also follow the form as it moves to other
records. It is confusing when the selection in the listbox stays put, but
the form has moved to another record.

Use the Current event of the form; it may be sufficient to just call
SelectorListBox_AfterUpdate (that is a valid procedure name!)
 
Create a hidden text box that is bound to the record source. Then set the
value of the list box to this hidden box.

Kelvin

Jerry said:
Thanks for the reply.
I'm not sure I made the problem as clear as I should have. The form is
steered to the record selected in the listbox with this code:

Private Sub SelectorListBox_AfterUpdate()
' Find the record that matches the control.
If Me!SelectorListBox <> "#Deleted" Then
Me.RecordsetClone.FindFirst "[ApplicationID] = " &
Me![SelectorListBox]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This works fine for this purpose. The problem is that if the user moves to
another record in the form, the highlited 'selected item' in the listbox
does not follow the position of the form in the recordset. In other words,
I have the form following the selection in the listbox but I need the
selected item in the listbox to also follow the form as it moves to other
records. It is confusing when the selection in the listbox stays put, but
the form has moved to another record.

Naresh Nichani MVP said:
Hi:

You could use the Form Filter property to filter for a specific record. If
ListBox is unbound trap the "AfterUpdate" event of ListBox with some code
like this

Me.Filter = "[CustomerName] = '" & Me.List0.Value & "'"
Me.FilterOn = True

This assumes you are filtering on a CustomerName field wth the value from
ListBox.

You can turn "AllowAdditions" and "AllowDeletions" to form to false.

Regards,

Naresh Nichani
Microsoft Access MVP


Jerry said:
I'm using an unbound listbox as a record selector for a form which works
fine. The problem is that there are other ways for the user to move from
record to record in the form. How can I make the listbox's selected item
follow the current record in the form without binding it to the forms record
source?
 
Thanks for the suggestion, but that just resets the form's selected record
back to what was previoulsy selected in the list box.

Bas Cost Budde said:
Jerry said:
Thanks for the reply.
I'm not sure I made the problem as clear as I should have. The form is
steered to the record selected in the listbox with this code:

Private Sub SelectorListBox_AfterUpdate()
' Find the record that matches the control.
If Me!SelectorListBox <> "#Deleted" Then
Me.RecordsetClone.FindFirst "[ApplicationID] = " &
Me![SelectorListBox]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This works fine for this purpose. The problem is that if the user moves to
another record in the form, the highlited 'selected item' in the listbox
does not follow the position of the form in the recordset. In other words,
I have the form following the selection in the listbox but I need the
selected item in the listbox to also follow the form as it moves to other
records. It is confusing when the selection in the listbox stays put, but
the form has moved to another record.

Use the Current event of the form; it may be sufficient to just call
SelectorListBox_AfterUpdate (that is a valid procedure name!)
 
Thanks Kelvin, that works. In fact, I found that I can bypass the textbox
and just use the key of the table the form is based on, like so...

Private Sub Form_Current()
'Force SelectorListBox's selected item to reflect changes
'in the form if the user moves to another record using
'another of the forms controls...
' Me.SelectorListBox = Me.Text30
Me.SelectorListBox = ApplicationID 'so SelectorListBox's selection
follows the
Me.SelectorListBox.Requery 'record selected by the form's other
controls
End Sub

Kelvin said:
Create a hidden text box that is bound to the record source. Then set the
value of the list box to this hidden box.

Kelvin

Jerry said:
Thanks for the reply.
I'm not sure I made the problem as clear as I should have. The form is
steered to the record selected in the listbox with this code:

Private Sub SelectorListBox_AfterUpdate()
' Find the record that matches the control.
If Me!SelectorListBox <> "#Deleted" Then
Me.RecordsetClone.FindFirst "[ApplicationID] = " &
Me![SelectorListBox]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This works fine for this purpose. The problem is that if the user moves to
another record in the form, the highlited 'selected item' in the listbox
does not follow the position of the form in the recordset. In other words,
I have the form following the selection in the listbox but I need the
selected item in the listbox to also follow the form as it moves to other
records. It is confusing when the selection in the listbox stays put, but
the form has moved to another record.

Naresh Nichani MVP said:
Hi:

You could use the Form Filter property to filter for a specific
record.
If
ListBox is unbound trap the "AfterUpdate" event of ListBox with some code
like this

Me.Filter = "[CustomerName] = '" & Me.List0.Value & "'"
Me.FilterOn = True

This assumes you are filtering on a CustomerName field wth the value from
ListBox.

You can turn "AllowAdditions" and "AllowDeletions" to form to false.

Regards,

Naresh Nichani
Microsoft Access MVP


I'm using an unbound listbox as a record selector for a form which works
fine. The problem is that there are other ways for the user to move from
record to record in the form. How can I make the listbox's selected item
follow the current record in the form without binding it to the forms
record
source?
 
Back
Top