Can't change a form's recordsource

J

Johnny Bright

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
 
A

Allen Browne

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
 

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