Listbox to subform refresh via code

  • Thread starter Thread starter Ynot
  • Start date Start date
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??
 
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.
 
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.
 
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.
 
Back
Top