Removing a Select query from the RowSource of a list box.

G

Guest

2003/XP/Novice

Good Evening
When I open my form, the first line of code below puts a Select query into
the rowSource of a list box on the subform: fsubSelectRecord. This works OK.

Private Sub Form_Open(Cancel As Integer)
Me!fsubSelect.Form!lstSelectRecord.RowSource = "qrySelectPageOrder"
'make the combo the same as the destination
Me.cboLocalDestination = Me!LocalDestinationID
'prevent the "The OLE object is empty" error message
'by setting focus on a control on the main form
Me.cboLocalDestination.SetFocus
'Me.Refresh
Me!fsubSelect.Form!lstSelectRecord.Requery
End Sub

When I close the form, the line of code below is supposed to remove the
query from the RowSource.

Private Sub Form_Close()
Me!fsubSelect.Form!lstSelectRecord.RowSource = ""
End Sub

But I get the error:
Run time error '2445'
You entered an expression that has an invalid reference to the property
Form/Report.

I am want to null the RecordSource because the subform is used with multiple
forms and I load a different query with each form.

Thank you

Peter
 
D

Duane Hookom

There is no need to set the property to null or a zero-length-string when
the form is closed. The property value does not "stick" unless you set the
property in design view and then save the subform control. Try it. You
should find the properties set with code while in form view do not persist
once the form is closed.
 
G

Guest

Thank you Duane--you're completely correct. How interesting? Sometimes less
is better.

Originally I had a Select Query in the RowSource. I was bewildered because I
was sure the code worked OK previously. I now realise that the line of code
stopped working when I placed the query programmatically.

Thanks

Peter
 

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