Unable to Close Form

A

Allan Smulling

Hi,

I'm having a bit of difficulty closing a form. Specifically I receive the
error message:

"This action can't be carried out while processing a form or report event."

The form in question "frmAddPatient" has code where it uses an SQL query to
to check if a patient already exists. The code that does this is triggered
after the user types in a medical record number and moves to the
"txtFirstName" field:

**** Start Code ****

Dim strPatientDuplicate As String
Dim rsPatientDuplicate As ADODB.Recordset
Dim intResponse As Integer

'Check to see if Patient is already in database by querying the MRNo.
'Build SQL statement to test.

strPatientDuplicate = "SELECT MRNo, FirstName, MiddleName, LastName FROM
PatientList WHERE MRNo = '" & Me.txtMRNo & "'"

'Connect to database
Call SetConnection

Set rsPatientDuplicate = Nothing
Set rsPatientDuplicate = New ADODB.Recordset
With rsPatientDuplicate
.CursorType = adOpenStatic
.Open strPatientDuplicate, cnPatientMeds
End With

'If the record set contains information then we have a duplicate record
If Not rsPatientDuplicate.BOF And Not rsPatientDuplicate.EOF Then
intResponse = MsgBox("Patient: " & [rsPatientDuplicate]![FirstName]
& (" " + [rsPatientDuplicate]![MiddleName]) & " " &
[rsPatientDuplicate]![LastName] & " is already in the database." & Chr(13) & _
"Do you want to view this patient's med list?",
vbOKCancel, "Duplicate Patient Found")
If intResponse = vbOK Then
strMRNo = Me.txtMRNo
cnPatientMeds.Close
DoCmd.OpenForm "frmMedication"
Call ClearControlsOnForm
[Forms]![frmMedication]![lstMedList].SetFocus
DoCmd.Close acForm, "frmAddPatient"

End If

If intResponse = vbCancel Then
Call ClearControlsOnForm
txtMiddleName.SetFocus
txtMRNo.SetFocus
cnPatientMeds.Close
End If
End If

Set rsPatientDuplicate = Nothing


End Sub

**** End Code ****

I run into this problem when I try to do:

docmd.close acform, "frmAddPatient"

either from within the example code, or from within the code on the form
that it just opened.

Any advise?

Thanks,
Allan
 

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