I'm getting an error due to referential integrity, the error is "you can not change record because a related record is required in table.” If I click back a record and then click forward to the current record and click enter the record takes with out producing an error. I'm confused
Here are my tables
tblMain
IDTool (KEY)
Year
ToolNum
DesignStart
StartDate
CompleteDate
WeeksToBuild
TotalHr
tbl_sub_Main
AutoIDTool (KEY)
IDTool (1 to many)
ToolNum
Year
WeekNum
JobHr
JobType
Here are my tables
tblMain
IDTool (KEY)
Year
ToolNum
DesignStart
StartDate
CompleteDate
WeeksToBuild
TotalHr
tbl_sub_Main
AutoIDTool (KEY)
IDTool (1 to many)
ToolNum
Year
WeekNum
JobHr
JobType
Code:
Option Compare Database
Option Explicit
Private Sub Enter_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim wtb As Integer
Dim r As Integer
Dim sr As Integer
Dim x As Integer
Dim y As Integer
Dim w As Integer
Dim th As Integer
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblsubMain", dbOpenDynaset)
wtb = Format(Me.CompleteDate(), "ww") - Format(Me.StartDate(), "ww")
Me.WeeksToBuild = wtb
x = Format(Me.CompleteDate(), "ww")
y = wtb + x
w = Format(Me.StartDate(), "ww")
th = Me.TotalHr / wtb
y = wtb + w
For x = w To y
If x < y Then
rst.AddNew
rst("WeekNum") = x
rst("JobHr") = th
rst.Update
End If
Next x
End Sub