Form Not closing using docmd

Paul Cooke

Registered User.
Local time
Today, 23:43
Joined
Oct 12, 2001
Messages
288
Hi guys - Could someone please advise me why my form is not closing please -I am getting a Run-time Error 2585 "This action can't be carried out whilst processing a form or a report"

The process I am using is

I open a form called "Select" select a name from the listbox (which is populated from a table called 'Patients' using a Select Qry) and click in an option group to open the form "Treatment"

The "Treatment" Form has 2 hidden controls TreatmentID & PatientID. The TreatmentID is the PK of the Treatment table but the PatientID is populated from the listbox on the form "Select" depending on what name is chosen there.

Once the Treatment form is opened all the controls are diasbled (by default) apart from the first one cboName. If the user does not enter anything in here and tabs out of it the next control cboDetails enables and has the focus. If the user tries to leave this control empty the Lostfocus event triggers as shown .....

Code:
Private Sub cboProductonEventTitle_LostFocus()
'Checks to see if a name has been entered in the Name control and details control if both are empty prompts user to try again or cancel the entry
 
If IsNull(Me.cboProductonEventTitle) = True Then
    Beep
    If bolDoExit = False Then
    MsgResponse = MsgBox("As You have not entered a Production \ Employer Name or a Production \ Event Title, you can not continue entering details on this database form." & vbCrLf & vbCrLf & _
    "If The Patient is with you, please complete a paper treatment form, ensuring you get full details of who they work for, if applicable" _
    & vbCrLf & vbCrLf & "Do You want to cancel this form?", vbQuestion + vbYesNo, "Cancel Data Entry")

If MsgResponse = vbNo Then
    MsgBox "Please enter either a Production \ Employer Name" & vbCrLf & "or a Production \ Event Title to continue", vbInformation + vbOKOnly, "Continue"

Else

If MsgResponse = vbYes Then
    Me.Undo
    If Me.Dirty = True Then
    Me.Dirty = False

    End If
    DoEvents
    DoCmd.OpenForm "Navigation"
    DoCmd.Close acForm, "NewTreatment"
    bolDoExit = True


                End If
            End If
        End If
    End If
End Sub

The code errors out if the user opts to cancel the data entry (VbYes) and highlights the line

Code:
   DoCmd.Close acForm, "Treatment"

If I mark out this line the code runs fine but obviusley the Treatment form does not close. I have read loads on the net regarding this issue and thinnk it is because something is 'running' in the background but for the life of me I do not know what it is or how to stop it !!

Any advice will be gratefully recieved

Many thanks

Paul

(sorry for the lengthy post but I wanted to try annd give a full picture of the problem!)
 
Try this revision

Don't forget to indent you code correctly

Code:
Private Sub cboProductonEventTitle_LostFocus()
'Checks to see if a name has been entered in the Name control and details control if both are empty prompts user to try again or cancel the entry
    
    If bolDoExit = True Then
        DoCmd.OpenForm "Navigation"
        DoCmd.Close acForm, "NewTreatment"
        Exit Sub
    End If
 
    If IsNull(Me.cboProductonEventTitle) = True Then
        Beep
        If bolDoExit = False Then
            MsgResponse = MsgBox("As You have not entered a Production \ Employer Name or a Production \ Event Title, you can not continue entering details on this database form." & vbCrLf & vbCrLf & _
            "If The Patient is with you, please complete a paper treatment form, ensuring you get full details of who they work for, if applicable" _
            & vbCrLf & vbCrLf & "Do You want to cancel this form?", vbQuestion + vbYesNo, "Cancel Data Entry")
        
            If MsgResponse = vbNo Then
                MsgBox "Please enter either a Production \ Employer Name" & vbCrLf & "or a Production \ Event Title to continue", vbInformation + vbOKOnly, "Continue"
            Else
        
                If MsgResponse = vbYes Then
                    Me.Undo
                    If Me.Dirty = True Then
                        Me.Dirty = False
                    End If
                    bolDoExit = True
                End If
            End If
        End If
    End If
    If bolDoExit = True Then
        DoCmd.OpenForm "Navigation"
        DoCmd.Close acForm, "NewTreatment"
        Exit Sub
    End If
    

End Sub
 
Hi David thanks for the reply and the revised code - sadly it did not work still get the same error on the same line?

for further information the "Select" form remains open after intiailly going through the process to get to the Treatment form. If for example I try to open the treatment form directly (without going through the 'navigation process' I get the following error

Run-time Error 2450 MS cannotont find the referenced form 'Select'

I am saying this because I'm thinking there is something running on the select form running when trying to close the treatment form (when I go through to it using the proper navigation process as described in my first post.

Thanks for any further help you can offer
 
Are you saying you have a form named Select?

If so rename it. This is an Access Reserved word and could be the issue
 
sorry it is actually called "SelectPatient" was trying to abbriviate things for speed !
 
How are you referencing the PatientID from the SelectPatient form?
 
Using a select Query from the PatientDetails table as below

Code:
SELECT PatientDetails.PatientID, PatientDetails.PatientFirstName, PatientDetails.PatientSurname, PatientDetails.PatientDOB, PatientDetails.HomeAddressPostCode, PatientDetails.PatientOccupationID, PatientOccupations.PatientOccupation FROM PatientOccupations RIGHT JOIN PatientDetails ON PatientOccupations.PatientOccupationID = PatientDetails.PatientOccupationID ORDER BY PatientDetails.PatientFirstName, PatientDetails.PatientSurname;
 
not sure if it helps but if i go through the treatment form ensuring data is entered in the controls get to the last control (which is basically coded to do the same - close Treatment and open Navigattion - it works fine?
 
Can you post a sample of your app to look at.
 
hmmm not sure why I have tried to use as save as but it is not giving me any options to use a different format ?

it is saying .. .accdb Im assuming that is not compatible with your end?
 
just read through a few posts on backward compatibilty and I don't think you will be able to open the DB even though it is created as a 2007 DB I must be using some of the 2010 'new extras' that stop you from opening it!

not sure what to do now - any ideas as I really need to get this issue resolved !
 
Can you create a blank accdb in 2007 and import the 2010 into it
 
Hi David nothing doing I'm afraid - I have tried on my machine and my partners (who has 2007 on it) it keeps saying unrecognised format.

I can't even import the tables ect into a 2007 open db.

So it seems we are stuck now - not sure what else to do?

thanks again
 
Hi David just wanted to give you an update on the problem you were helping me with...

I have re-arranged some code in other related forms to the form we discussed. Specifically in how they open and close and in what order they close when they have been either completed or finished.

It has taken some time to work it out and to be honest I still do not know what was causing the original error but it is now all working fine albeit in a longwinded way !

I would love to post the 'fix' here for others to reference but again I'm not actually sure what amendments I made, fixed it !

I just wanted to say thanks you for all your efforts and time in trying to help me with this .....on to the next problem soon no doubt :rolleyes:

Many thanks again

Paul
 
Sorry I could not help you due to version conflict, but glad you got it resolved.:)
 

Users who are viewing this thread

Back
Top Bottom