P
Pete Davis
Okay, again with the real estate app.
I have two main forms: ForSale and Rental
Both forms have the same subform : PropertyDetails.
Because the relationship is 1 PropDetails to many of either of the others
(in actuality it's a 1:1 relationship, with ForSale or ForRent), the
subforming is sort of backwards and it's causing some problems. I need to
save a PropertyDetails record and populate the PropertyDetailsID in ForSale
or Rental before I can save either.
To handle the problem, I've created the following code in the BeforeInsert
event:
If IsNull(Me.PropertyDetails.Form!PropertyDetailsID.Value) Then
Me.PropertyDetails.Form!ListingAgent.Value =
Me.PropertyDetails.Form!ListingAgent.Value
Me.PropertyDetailsID.Value =
CInt(Me.PropertyDetails.Form!PropertyDetailsID.Value)
End If
The first part is checking that PropertyDetails has not yet been assigned an
ID. The next line is simply making the form dirty (setting dirty from here
causes a focus error). Then I assign the PropertyDetailsID to the ForSale or
Rental form.
Everything looks great on the forms (both the ForSale and PropertyDetails
record get their new autonumbers), but when I try to do anything on the
sub-form or save the main form, I get "You cannot add or change a record
because the related record is required in table PropertyDetails.
So, somehow, I need to force the property details record to save, but using
DoCmd.RunCommand acCmdSaveRecord causes the same error. Any ideas?
Thanks.
Pete
I have two main forms: ForSale and Rental
Both forms have the same subform : PropertyDetails.
Because the relationship is 1 PropDetails to many of either of the others
(in actuality it's a 1:1 relationship, with ForSale or ForRent), the
subforming is sort of backwards and it's causing some problems. I need to
save a PropertyDetails record and populate the PropertyDetailsID in ForSale
or Rental before I can save either.
To handle the problem, I've created the following code in the BeforeInsert
event:
If IsNull(Me.PropertyDetails.Form!PropertyDetailsID.Value) Then
Me.PropertyDetails.Form!ListingAgent.Value =
Me.PropertyDetails.Form!ListingAgent.Value
Me.PropertyDetailsID.Value =
CInt(Me.PropertyDetails.Form!PropertyDetailsID.Value)
End If
The first part is checking that PropertyDetails has not yet been assigned an
ID. The next line is simply making the form dirty (setting dirty from here
causes a focus error). Then I assign the PropertyDetailsID to the ForSale or
Rental form.
Everything looks great on the forms (both the ForSale and PropertyDetails
record get their new autonumbers), but when I try to do anything on the
sub-form or save the main form, I get "You cannot add or change a record
because the related record is required in table PropertyDetails.
So, somehow, I need to force the property details record to save, but using
DoCmd.RunCommand acCmdSaveRecord causes the same error. Any ideas?
Thanks.
Pete