Can't change a form's recordsource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to change a form's recordsource depending on whether or not a text
box on my lookup form is filled in. The two different queries use different
parameters but for some reason, the form will only look at the first query,
the one I have set as the form's datasource.
Private Sub Form_Open(Cancel As Integer)

If Forms!frmLookup.txtPatient.Value = "" Then

Me.RecordSource = "qryPatientsFilter"
Else
Me.RecordSource = "qryPatientsFilterLast"

End If
End Sub
What am I doing wrong?

Thanks

J
 
You are testing txtPatient for a zero-length string. That is not the same as
null.

Try:
If IsNull(Forms!frmLookup.txtPatient) Then

Another possible issue is that the form could be dirty with a record that
cannot be saved (e.g. if a required field is missing, or a validation rule
not met.) Add this line before the others:
If Me.Dirty Then Me.Dirty = False
 
Back
Top