Cannot add or change record

A

azu_daioh

I'm getting this error message on one of the database but not on the
other. "You cannot add or change a record because a related record is
required in table <name>. (Error 3201)"

Both databases have similar relatioships/design so I dont know why
it's working on one and not the other.

here's the code:
Private Sub License__AfterUpdate()
Dim xLic As String

xLic = Nz(DLookup("[License#]", "Doctor Basic Info", _
"[License#] = '" & Me.[License#] & "'"), "0")

If xLic = "0" Then
MsgBox "Doctor's license# is currently not in the database." &
Chr(13) _
& "Please complete the 'Basic Doctor Info' before
proceeding.", _
vbCritical, "Doctor Record Not Found"

DoCmd.OpenForm "Doctor Table", acNormal
DoCmd.GoToRecord , , acNewRec
Forms![Doctor Table]![License#] = Forms![Add New Monthly
Payment Record]![License#]

End If

End Sub

In the database where the code works I have this relationship
[Doctor Basic Info] 1-Many [Monthy Activity]

[Monthly Activity] is the record source for Forms![Add New Monthly
Payment Record]
[Doctor Basic Info] is the record source for Forms![Doctor Table]


In the database where the code does not work:
[tbl_ClaimDetails] 1-Many [tbl_Doctors]

And this is the code that doesnt work:
Private Sub drLicense_AfterUpdate()
Dim xLic As String

xLic = Nz(DLookup("[drLicense]", "tbl_Doctor", _
"[drLicense] = '" & Me.[drLicense] & "'"), "0")

If xLic = "0" Then
MsgBox "Doctor's license# is currently not in the database." &
Chr(13) _
& "Please complete the 'Basic Doctor Info' before
proceeding.", _
vbCritical, "Doctor Record Not Found"

DoCmd.OpenForm "frm_Doctor", acNormal
DoCmd.GoToRecord , , acNewRec
Forms![frm_Doctor]![drLicense] = Forms![frm_Doctors]![License#]

End If
End Sub
 
A

azu_daioh

Oooops! I typed it in reverse
In the database where the code does not work:
[tbl_ClaimDetails] 1-Many [tbl_Doctors]

The relationship is
[tbl_Doctors] 1-Many [tbl_ClaimDetails]
 
A

azu_daioh

Another typo:
Forms![frm_Doctor]![drLicense] = Forms![frm_Doctors]![License#]

should say:
Forms![frm_Doctor]![drLicense] = Forms![frm_ClaimDetails]![License#]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top