Controls disappear when form's recordsource returns no records

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