F
fascal
I get the runtime error, 'that I cannot add or change a record because a
related record is required in table 'tblPatients'.
When I check tblPatients, the PatientID that the form is looking for is
there. Below is the code. it has been working previously. It highlights
yeloow at the rs.Update. When I pass my cursor over the PatientID and the
rs.update, the numbers are there.
Any help asap would be much appreciated.
****************************************
Private Sub Form_AfterUpdate()
If AddMark = "Yes" Then 'If a new patient was added, need to create
'a dispo record for them
If IsOpen("frmGetNewEnrollDispo") Then
Dim db As Database
Dim rs As Recordset
Dim sql As String
Dim newid As Long
Dim msg As String
Dim ttl As String
sql = "SELECT * FROM tblPatientDispos WHERE PatientID=" & Me!PatientID
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
rs.AddNew
rs!PatientID = Me!PatientID
rs!AdmitDate = Forms!frmGetNewEnrollDispo!AdmitDate
newid = rs!DispoID
rs.Update
rs.Close
sql = "INSERT INTO tblPatientVenues (DispoID, StartDate, Venue) "
sql = sql & "VALUES (" & newid & ", #" &
Forms!frmGetNewEnrollDispo!AdmitDate & "#,"
sql = sql & Forms!frmGetNewEnrollDispo!Venue & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL sql
DoCmd.SetWarnings True
msg = ""
If Me.ChooseStatus = "Inactive Patients" Then
msg = "The patient you just added is active. The patient's
record will not be available again until you " & _
"select 'Show active patients' or 'Show all patients'."
End If
If msg <> "" Then
ttl = "Patient not available in this view"
DoCmd.Beep
MsgBox msg, vbInformation + vbOKOnly, ttl
End If
End If
AddMark = "No"
DoCmd.Close acForm, "frmGetNewEnrollDispo"
End If
Dim Dummy As Integer
Dummy = DisableSave()
related record is required in table 'tblPatients'.
When I check tblPatients, the PatientID that the form is looking for is
there. Below is the code. it has been working previously. It highlights
yeloow at the rs.Update. When I pass my cursor over the PatientID and the
rs.update, the numbers are there.
Any help asap would be much appreciated.
****************************************
Private Sub Form_AfterUpdate()
If AddMark = "Yes" Then 'If a new patient was added, need to create
'a dispo record for them
If IsOpen("frmGetNewEnrollDispo") Then
Dim db As Database
Dim rs As Recordset
Dim sql As String
Dim newid As Long
Dim msg As String
Dim ttl As String
sql = "SELECT * FROM tblPatientDispos WHERE PatientID=" & Me!PatientID
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
rs.AddNew
rs!PatientID = Me!PatientID
rs!AdmitDate = Forms!frmGetNewEnrollDispo!AdmitDate
newid = rs!DispoID
rs.Update
rs.Close
sql = "INSERT INTO tblPatientVenues (DispoID, StartDate, Venue) "
sql = sql & "VALUES (" & newid & ", #" &
Forms!frmGetNewEnrollDispo!AdmitDate & "#,"
sql = sql & Forms!frmGetNewEnrollDispo!Venue & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL sql
DoCmd.SetWarnings True
msg = ""
If Me.ChooseStatus = "Inactive Patients" Then
msg = "The patient you just added is active. The patient's
record will not be available again until you " & _
"select 'Show active patients' or 'Show all patients'."
End If
If msg <> "" Then
ttl = "Patient not available in this view"
DoCmd.Beep
MsgBox msg, vbInformation + vbOKOnly, ttl
End If
End If
AddMark = "No"
DoCmd.Close acForm, "frmGetNewEnrollDispo"
End If
Dim Dummy As Integer
Dummy = DisableSave()