Listbox to subform refresh via code

Y

Ynot

I have a form with a listbox on it and an subform. The subform is queried
by the selection in the listbox. All of this works!!



I have added another feature on the form where the rows of the listbox can
be reduced based on a search argument. I.E. if you want only people with
the last name "Smith" in the listbox, you type Smith into a field and click
a search button. I use this to alter the data source of the listbox to
include only items with the name "Smith." That also works perfectly and a
subsequent selection queries the subfiorm and works.



What I want to do is when the results of the search leave only one item in
the listbox, I want that one item to be selected and cause the subform to
requery on that item. I've tried everything and this is what I currently
have that does not work!



If List0.ListCount = 1 Then



List0.Selected(0) = True

Me.RecordsetClone.FindFirst "[ID] = " & Me![List0]

Me.Bookmark = Me.RecordsetClone.Bookmark

Form.Refresh

[FrmMemberData].Requery



End If



What can I do to automatically query the subform if only one item remains in
the listbox??
 
O

OldPro

I have a form with a listbox on it and an subform. The subform is queried
by the selection in the listbox. All of this works!!

I have added another feature on the form where the rows of the listbox can
be reduced based on a search argument. I.E. if you want only people with
the last name "Smith" in the listbox, you type Smith into a field and click
a search button. I use this to alter the data source of the listbox to
include only items with the name "Smith." That also works perfectly and a
subsequent selection queries the subfiorm and works.

What I want to do is when the results of the search leave only one item in
the listbox, I want that one item to be selected and cause the subform to
requery on that item. I've tried everything and this is what I currently
have that does not work!

If List0.ListCount = 1 Then

List0.Selected(0) = True

Me.RecordsetClone.FindFirst "[ID] = " & Me![List0]

Me.Bookmark = Me.RecordsetClone.Bookmark

Form.Refresh

[FrmMemberData].Requery

End If

What can I do to automatically query the subform if only one item remains in
the listbox??

Instead of [FrmMemberData].Requery, try Forms!Mainformname!
FrmMemberData.Form.Requery where Mainformname is your main form name.
 
Y

Ynot

Still the same problem.



I changed it. This is the new statement:



Forms!FrmMemberList!FrmMemberData.Requery





When I select the one item it works just like if there were multiples. This
is my afterupdate code for the listbox:



Private Sub List0_AfterUpdate()

Me.RecordsetClone.FindFirst "[ID] = " & Me![List0]

Me.Bookmark = Me.RecordsetClone.Bookmark

Form.Refresh

[FrmMemberData].Requery

End Sub



Any other thoughts?????

OldPro said:
I have a form with a listbox on it and an subform. The subform is
queried
by the selection in the listbox. All of this works!!

I have added another feature on the form where the rows of the listbox
can
be reduced based on a search argument. I.E. if you want only people with
the last name "Smith" in the listbox, you type Smith into a field and
click
a search button. I use this to alter the data source of the listbox to
include only items with the name "Smith." That also works perfectly and
a
subsequent selection queries the subfiorm and works.

What I want to do is when the results of the search leave only one item
in
the listbox, I want that one item to be selected and cause the subform to
requery on that item. I've tried everything and this is what I
currently
have that does not work!

If List0.ListCount = 1 Then

List0.Selected(0) = True

Me.RecordsetClone.FindFirst "[ID] = " & Me![List0]

Me.Bookmark = Me.RecordsetClone.Bookmark

Form.Refresh

[FrmMemberData].Requery

End If

What can I do to automatically query the subform if only one item remains
in
the listbox??

Instead of [FrmMemberData].Requery, try Forms!Mainformname!
FrmMemberData.Form.Requery where Mainformname is your main form name.
 
Y

Ynot

It appears that the requery is working, the selection of the single item in
the listbox appears to not be working. When I manually select it, the
requery in my afterupdate works perfectly.

Just some more info on the problem....

Thanx.

OldPro said:
I have a form with a listbox on it and an subform. The subform is
queried
by the selection in the listbox. All of this works!!

I have added another feature on the form where the rows of the listbox
can
be reduced based on a search argument. I.E. if you want only people with
the last name "Smith" in the listbox, you type Smith into a field and
click
a search button. I use this to alter the data source of the listbox to
include only items with the name "Smith." That also works perfectly and
a
subsequent selection queries the subfiorm and works.

What I want to do is when the results of the search leave only one item
in
the listbox, I want that one item to be selected and cause the subform to
requery on that item. I've tried everything and this is what I
currently
have that does not work!

If List0.ListCount = 1 Then

List0.Selected(0) = True

Me.RecordsetClone.FindFirst "[ID] = " & Me![List0]

Me.Bookmark = Me.RecordsetClone.Bookmark

Form.Refresh

[FrmMemberData].Requery

End If

What can I do to automatically query the subform if only one item remains
in
the listbox??

Instead of [FrmMemberData].Requery, try Forms!Mainformname!
FrmMemberData.Form.Requery where Mainformname is your main form name.
 

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