Controls disappear when form's recordsource returns no records

K

KC

I have a form with two unbound combo boxes from which a user selects a
month and year of interest. The form also has textboxes whose control
sources are populated with the names of fields in my (as yet unrun)
stored procedure (actually it's a function). The form itself does not
have a recordsource defined.

There is also a command button on the form:

Private Sub Command4_Click()
Dim ldStrtDate As Date, ldEndDate As Date

Me.RecordSource = ""

Call GetDates(ldStrtDate, ldEndDate)

Me.InputParameters = "@StrtDate = '" + Format(ldStrtDate) +
"',@EndDate = '" + Format(ldEndDate) + "'"
Me.RecordSource = "fn_GetSumbyDate"

Me.Refresh
End Sub

Now, everthing works absolutely perfectly as long as the dates selected
by the user are valid (ie there are records in the tables that fall
within the specified dates). However, if the dates specified result in
no records being returned from the function, ALL FIELDS DISAPPEAR FROM
THE FORM.

Why?
How to fix?

Thanks in advance,
KC
 
S

Sylvain Lafontaine

No result, no fields.

You could test for an empty recordset and unbound the form if the recordset
is empty; however, if there are nothing to display, why should you care?

You can also activate the possibility of Allowing Addtions for the form but
again, why care?
 
R

Robert Morley

I don't know if it would be appropriate for what you're trying to do, but
would it make sense to move things like the command button (Command4) to the
form header or form footer? Or am I misunderstanding the problem?



Rob
 

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