B
bob bob via AccessMonster.com
I have a subform that consists of a continuous form that gets its data from
one of two queries. I want to change the recordsource between queries when
a button on the main form is clicked.
My onclick code is
Private Sub button_Click()
If Me!button.Caption = "query1" Then
Me!button.Caption = "query2"
Forms![main]![sub].Form.RecordSource = "query2"
Else
Me!button.Caption = "query2"
Forms![main]![sub].Form.RecordSource = "query1"
End If
Forms![main]![sub].Form.Requery
End Sub
The problem is that the subform shows no records after the code is run,
even though each query works fine if I manually enter it as the
recordsource before opening the form. In fact, if I open the subform on its
own, and run the same code using a button on the subform, it works fine.
It's only when I make the change through a main form onclick event that the
subform goes blank.
I've tried every combination of refresh, repaint, and requery that I can
think of, but the subform stays empty. Any ideas? Do I need to close and
re-open the main form to make this work?
one of two queries. I want to change the recordsource between queries when
a button on the main form is clicked.
My onclick code is
Private Sub button_Click()
If Me!button.Caption = "query1" Then
Me!button.Caption = "query2"
Forms![main]![sub].Form.RecordSource = "query2"
Else
Me!button.Caption = "query2"
Forms![main]![sub].Form.RecordSource = "query1"
End If
Forms![main]![sub].Form.Requery
End Sub
The problem is that the subform shows no records after the code is run,
even though each query works fine if I manually enter it as the
recordsource before opening the form. In fact, if I open the subform on its
own, and run the same code using a button on the subform, it works fine.
It's only when I make the change through a main form onclick event that the
subform goes blank.
I've tried every combination of refresh, repaint, and requery that I can
think of, but the subform stays empty. Any ideas? Do I need to close and
re-open the main form to make this work?