Forms not linking

  • Thread starter Thread starter Walter
  • Start date Start date
W

Walter

I am opening a form(subform) from a command button on
another form. The button's code is:
DoCmd.OpenForm "frmPlantingDetails", , , "PlantingID =" &
Me.PlantingID

The form opens but the PlantingID field remains blank.
The filter property on the data tab of the form's property
sheet shows PlantingID = 13(the PlantingID of the record
the form was opened from. When I enter data and try to
save it I get an error msg "You cannot add or change a
record because a related record is required in
tblPlantings". I have checked the relationship between
the two tables. Could there be a problem with Access
because I was having problems with two combo boxes not
working? I checked everything several times comparing to
ones that were working and could find nothing wrong. I
finaly deleted the boxes from the form and added them back
set up the same way they were and now they work fine.
Thanks,
Walter
 
From your description of the problem, it sounds to me as if
there is no record in the table referenced as the
ControlSource to frmPlantingDetails with a plantingId of
13. Are all the other bound controls blank?

Also, that there is no record in the table referenced as
the ControlSource to the calling form with a plantingId of
13 either. Could it be that the calling form was adding an
entry with plantingId of 13 but had not completed the
operation before the command button was clicked?

Hope That Helps
Gerald Stanley MCSD
 
There is a complete record with PlantingID = 13. I
entered 6 or 7 records in the main form checking it out
before I started on the details form. I open the main
form and it displays the first record(PlantingID 13). I
click the button and the details form opens. There is a
combo box for varieties on the details form that uses
criteria from the crop combo box on the main form to limit
the list and this is working.
Thanks again,
Walter
 
Are both forms using the same table? If not, is there a
record for plantingId 13 in the second table?

Regards
Gerald Stanley MCSD
 
The two forms are based on two seperate tables. The main
form's table is frmPlantings with primary key PlantingsID
(autonumber). The subform's table is frmPlantingDetails
with primary key PlantingDetailsID(autonumber). This form
also has a PlantingID field which is linked to
frmPlantings PlantingID field with a one to many
relationship with referential integrity enabled. There
are no records in tblPlantingDetails because the forms are
not linking and so will not let me save any records.
Thanks,
Walter
 
Your first e-mail said that the plantingId was not getting
populated on the second form when you passed the plantingId
of 13 which is not surprising as you now say that there are
no records in the second table.

To populate the plantingId field under thse circumstances,
I suggest that you also pass the plantingId as the OpenArg
(the 7th argument of DoCmd.OpenForm). You will then need
to put some code into the Load event handler of the second
form to populate the plantingId field when the filter
criteria returns no records.

Hope That Helps
Gerald Stanley MCSD
 
Back
Top