Re: run-time error 3201

Tech-Archive recommends: Fix windows errors by optimizing your registry



I suspect that since you've just created the new patient, that it may not
have been written to the table yet. This may just be a timing problem. As
you mentioned, by the time you get the error and go to the table, the value
is there. Before you open the RecordSet try the line:

DbEngine.Idle dbRefreshCache

Also, there is a more efficient way for the following:

> DoCmd.SetWarnings False
> DoCmd.RunSQL sql
> DoCmd.SetWarnings True

Instead of these 3 lines, try

db.Execute sql, dbFailOnError

This will run without the "do you want to..." prompt, but will return an
error if the statement fails to complete. It also saves having to remember
to turn Warnings back on.

--
Wayne Morgan
MS Access MVP


"fascal" <fascal@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0A9A5E3E-64C0-4B19-9B55-900E57D3F7F8@xxxxxxxxxxxxxxxx
>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()
>
>
>


.



Relevant Pages

  • Re: run-time error 3201
    ... "Wayne Morgan" wrote: ... >> related record is required in table 'tblPatients'. ... When I pass my cursor over the PatientID and the ... >> Dim Dummy As Integer ...
    (microsoft.public.access.modulesdaovba)
  • Re: Updating a table in a form
    ... I am getting an error message ... > PatientID (primary key) ... > PatientID (foreign key from tblPatients) ...
    (microsoft.public.access.macros)
  • Re: Updating a table in a form
    ... Is there a way I can change the data that is on the subform? ... > PatientID (foreign key from tblPatients) ... >> Ryan W ...
    (microsoft.public.access.macros)
  • Re: Serial one-to-many tables
    ... PatientID (foreign key from tblPatients) ... LocationID ... then a 2nd level subform, bound to tblPatProcLocations, with a combobox ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Updating a table in a form
    ... PatientID (primary key) ... PatientID (foreign key from tblPatients) ... > autoform: datasheet wizard.) ...
    (microsoft.public.access.macros)