J
John Petty
I am trying to add a new record to a table using a form. Everything looks
fine until the code hits frs.update. I then get the following error:
"Cannot add or change record because a related record is required in table
...."
The field that is causing the error is WheelID, but the way the table (that
I am adding the record to) is created the WheelID is a foreign key that has a
one to many relationship from it's own table (i.e. it tags the record to the
WheelID) . How can I get this table to accept the WheelID?
Dim frs As DAO.Recordset
Dim FWID As Variant
Dim FPR As Variant
Dim FPS As Variant
Dim FAI As Variant
Dim FIT As Variant
Dim FRQ As Variant
Dim FCE As Variant
Dim FDR As Date
Dim FDE As Date
Dim FWC As Variant
Dim FWF As Variant
Dim FPN As Variant
Dim FLC As Variant
Dim FLR As Variant
Dim FLI As Variant
Dim FLA As Variant
Dim FCC As Variant
Dim FCR As Variant
Dim FIH As Variant
Dim FIA As Variant
Dim FFL As Variant
' Activate project table and verify that the new analysis iteration
' does not currently exist
With Forms!fmMasterForm.sfmFeaData.Form
If !tbFIteration.Value = DLookup("[FIteration]", "[tblFProj]",
"[WheelID] = " & !WheelID) Then
MsgBox ("Iteration Already exists.")
Exit Sub
Else
' Copy the Required fields to a dummy collector
With Forms!fmMasterForm.sfmFeaData.Form
FWID = !WheelID
FPR = !tbFWPNo.Value
FPS = !tblPStatusID.Value
FAI = !tblFAnalysisID.Value
FIT = !tbFIteration.Value
FRQ = !tbFRequestor.Value
FCE = !tbFCAE.Value
FDR = !tbRDate.Value
FDE = !tbPECD.Value
FWC = !tbFWeightCurrent.Value
FWF = !tbFWeightFEA.Value
FPN = !tbFPNotes.Value
FLC = !tbFLoadCorner.Value
FLR = !tbFLoadRadial.Value
FLI = !tbFLoadImpact.Value
FLA = !tbFLoadAir.Value
FCC = !tbFCycleCorner.Value
FCR = !tbFCycleRadial.Value
FIH = !tbFImpactHeight.Value
FIA = !tbFImpactAngle.Value
FFL = !tbfWFile.Value
End With
' Add the data into the tblfproj table and save record
Set frs = CurrentDb.OpenRecordset("tblFProj")
frs.AddNew
WheelID = FWID
FWProj = FPR
PStatusID = FPS
FAnalysisID = FAI
FIteration = FIT
FRequestor = FRQ
FCAE = FCE
FDateRequest = FDR
FDateEstimate = FDE
FWeightCad = FWC
FWeightFEA = FWF
FProjectNotes = FPN
FLoadCorner = FLC
FLoadRadial = FLR
FLoadImpact = FLI
FLoadAir = FLA
FCycleCornering = FCC
FCycleRadial = FCR
FImpactHeight = FIH
FImpactAngle = FIA
FFile = FFL
frs.Update
frs.Close
End If
End With
fine until the code hits frs.update. I then get the following error:
"Cannot add or change record because a related record is required in table
...."
The field that is causing the error is WheelID, but the way the table (that
I am adding the record to) is created the WheelID is a foreign key that has a
one to many relationship from it's own table (i.e. it tags the record to the
WheelID) . How can I get this table to accept the WheelID?
Dim frs As DAO.Recordset
Dim FWID As Variant
Dim FPR As Variant
Dim FPS As Variant
Dim FAI As Variant
Dim FIT As Variant
Dim FRQ As Variant
Dim FCE As Variant
Dim FDR As Date
Dim FDE As Date
Dim FWC As Variant
Dim FWF As Variant
Dim FPN As Variant
Dim FLC As Variant
Dim FLR As Variant
Dim FLI As Variant
Dim FLA As Variant
Dim FCC As Variant
Dim FCR As Variant
Dim FIH As Variant
Dim FIA As Variant
Dim FFL As Variant
' Activate project table and verify that the new analysis iteration
' does not currently exist
With Forms!fmMasterForm.sfmFeaData.Form
If !tbFIteration.Value = DLookup("[FIteration]", "[tblFProj]",
"[WheelID] = " & !WheelID) Then
MsgBox ("Iteration Already exists.")
Exit Sub
Else
' Copy the Required fields to a dummy collector
With Forms!fmMasterForm.sfmFeaData.Form
FWID = !WheelID
FPR = !tbFWPNo.Value
FPS = !tblPStatusID.Value
FAI = !tblFAnalysisID.Value
FIT = !tbFIteration.Value
FRQ = !tbFRequestor.Value
FCE = !tbFCAE.Value
FDR = !tbRDate.Value
FDE = !tbPECD.Value
FWC = !tbFWeightCurrent.Value
FWF = !tbFWeightFEA.Value
FPN = !tbFPNotes.Value
FLC = !tbFLoadCorner.Value
FLR = !tbFLoadRadial.Value
FLI = !tbFLoadImpact.Value
FLA = !tbFLoadAir.Value
FCC = !tbFCycleCorner.Value
FCR = !tbFCycleRadial.Value
FIH = !tbFImpactHeight.Value
FIA = !tbFImpactAngle.Value
FFL = !tbfWFile.Value
End With
' Add the data into the tblfproj table and save record
Set frs = CurrentDb.OpenRecordset("tblFProj")
frs.AddNew
WheelID = FWID
FWProj = FPR
PStatusID = FPS
FAnalysisID = FAI
FIteration = FIT
FRequestor = FRQ
FCAE = FCE
FDateRequest = FDR
FDateEstimate = FDE
FWeightCad = FWC
FWeightFEA = FWF
FProjectNotes = FPN
FLoadCorner = FLC
FLoadRadial = FLR
FLoadImpact = FLI
FLoadAir = FLA
FCycleCornering = FCC
FCycleRadial = FCR
FImpactHeight = FIH
FImpactAngle = FIA
FFile = FFL
frs.Update
frs.Close
End If
End With