saving value form main form to sub form...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.

I have a situation where a value from a combo box (named cboPayPeriod on a
Main form; source is form tblPayPeriods) needs to copy to a subform field
(named fkPerID). The code is as follows (but does not save the value):

If IsNull (Me!fkPerID) Then
Me!fkPerID = Me.Parent!cboPayPeriod
End If

When I try to save a record I get the following error: "You cannot add or
chnage a record because a related record is required in table 'tblPayPeriods'"

My DB is properly normalized (tblPayPeriods is linked to the Overtimefile
via the PerID fiield with PerID on the one side and fkPerID on the manyside),
but for some reason the value from the combo box won't transfer to the
flPerID field in the sub form. However, when I manually enter in a valid ID
number from tblPayPeriods, the record saves OK.

Any suggestions on what is happening here?

Thank you kindly (I'm very pressed for time to complete this project and any
assitance would be appreciated).

Mark :)
 
My DB is properly normalized (tblPayPeriods is linked to the Overtimefile
via the PerID fiield with PerID on the one side and fkPerID on the manyside),
but for some reason the value from the combo box won't transfer to the
flPerID field in the sub form. However, when I manually enter in a valid ID
number from tblPayPeriods, the record saves OK.

What are the Master Link Field and Child Link Field properties of the
Subform control? The Master should be either PerID or the name of the
combo box bound to PerID on the mainform; the Child should be fkPerID.

John W. Vinson[MVP]
 
Hello John.

As usual, you present excellent logic. I should have explained better in my
first post. The sub form is actually linked to the main form via
fkEmployeeID (child) and EmployeeID (master). The flEmployeeID field in the
Overtime table is a foreign key from the Employee Primary key filed in the
Employees table, as Employee fields are also shown on the main form. The
fkPerID field located in the Overtime table is a foreign key from the
PayPeriods table. Presumably, this is the reason for the code as presented
in my first post. FYI that the combo box (cboPayPeriod) is located in the
Form Header, and the Employee and Overtime stuff is located on the Detail
section of the form. I just don't understand why the fkPerID in the subform
takes a manual entry (as long as that entry is a valid Primary key value from
the tblPayPeriods table), and why the code dosn't transfer the value from the
cboPayPeriod combo box. So, with that, any ideas?

Mark :)
 
Please disregard my previous posts as I discovered my stupid mistake. I had
a zero in the default value space on the fkPerID filed in the Overtime file.
Removed the zero, and things work fine now.

Thanks.

Mark :)
 
Please disregard my previous posts as I discovered my stupid mistake. I had
a zero in the default value space on the fkPerID filed in the Overtime file.
Removed the zero, and things work fine now.

That's a stupid mistake all right - but it's not YOUR stupid mistake!
It's the mistake of the developers of Access, who assumed that any
numeric field should default by default to 0; this is handy for some
numeric fields but emphatically NOT for foreign keys.

John W. Vinson[MVP]
 
Back
Top