Chil/master fields filled automatically and cause a subform query to fail

  • Thread starter bob bob via AccessMonster.com
  • Start date
B

bob bob via AccessMonster.com

This is a new twist on a question I've posted previously.

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.

I've debugged the problem far enough to find that, although the
child/master fields on the main form start off blank, something in this
sequence fills them in and creates a relationship that makes the query come
up empty. Is there a way to block the child/master fields from auto-
filling?
 
R

Rob Oldfield

What are you using as master and child fields. Autonumber pk and long
integer or something else? What is being 'filled in'?
 
B

bob bob via AccessMonster.com

The main form derives data from a table with one field: studydate. The
subform queries another table to identify procedures done on that date, and
the button is meant to switch between studies completed and those still
pending. The master/child fields start off blank but are being filled in
with "studydate." As near as I can tell, the query is apparently trying to
draw data from the wrong table.
 
R

Rob Oldfield

So if it's getting data from the wrong table, does that explain your
problem? I can't recall ever using dates as a linking field before, but one
thing leaps immediately to mind... have you checked that neither side of the
relationship is storing time information that is causing the fields to be
unequal?
 
B

bob bob via AccessMonster.com

I've fixed the problem. There was no need for the main form to use the
date table as its object source. Once I eliminated the objectsource field
data on the main form, it stopped creating the master/child link I didn't
want.
 

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