form not closing

Paul Cooke

Registered User.
Local time
Today, 17:55
Joined
Oct 12, 2001
Messages
288
would someone mind having a look at the following code please - I can't work out why the form does not close on the doCmd bit at the bottom.

Code:
If IsNull(Me.cboProductionEmployerName) Then
vbResponse = MsgBox("You have not enterted a Production or Employer Name." & vbCrLf & vbCrLf & _
"Do you have a Production or Event Title?", vbQuestion + vbYesNo, "Production / Event Title")
If vbResponse = vbYes Then
Me.cboProductonEventTitle.Enabled = True
Me.cboProductonEventTitle.SetFocus
Else
If vbResponse = vbNo Then
vbResponse = MsgBox("As you do not have a Production or Employer Name or a Production or 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." & vbCrLf & vbCrLf & _
"Otherwise please click 'ok' below to continue.", vbInformation + vbOKOnly, "Cancel Data Entry")
If vbResponse = vbOK Then
MsgBox "Please put the form in question to one side and email Paul with the details", vbInformation, "Cancel Data Entry"
End If
DoCmd.Close acForm, ("Newtreatment"), acSaveNo

DoCmd.OpenForm "Navigation"

Many thanks for any adice offered.
 
I can think of three reasons this might occur...
- The form might not be open.
- The name you provided might be misspelled
- The form may run code in its Unload() event that cancels the close.
To monitor what forms are open you can type this in the immediate window...
Code:
for each frm in forms : debug.Print frm.name : next
...which will print a list of the open forms by name. That will help you troubleshoot the first two cases.
In the last case, see if there is a Sub Form_Unload(Cancel as Integer) on the named form and if so, set a breakpoint in it and see what it does. Does it cancel the form closing?
Cheers,
 
thanks for the reply

The form control name is spelt correctly and is open. there are events on the Sub form as follows

Code:
Private Sub Form_Current()
'Checks to see if a new record has been selected and looks up new number
If Me.NewRecord = True Then
    lngTrNum = DLookup("NextTreatmentNumber", "ReferenceNumbers")
    strTrPrefix = DLookup("TreatmentPrefix", "ReferenceNumbers")
    Me.txtTreatmentNumber = strTrPrefix & lngTrNum
End If
    
If IsNull(Me.txtPatientID) Then
      Me.txtPatientID = Forms!SelectPatient.lstPatients

End If

End Sub

Code:
Private Sub Form_Close()
'Automatically updates the reference number by 1
If Me.OpenArgs = "AddMode" Then
    lngTrNum = lngTrNum + 1
    Set rs = CurrentDb.OpenRecordset("ReferenceNumbers")
    rs.Edit
    rs.Fields("NextTreatmentNumber").Value = lngTrNum
    rs.Update
    rs.Close
    Set rs = Nothing

End If

End Sub

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
'Various messages to confirm correct data has been entered in relevent boxes
Const INPUTMASK_VIOLATION = 2279 Or 2113
Dim msg As String

   If DataErr = INPUTMASK_VIOLATION Then
   Select Case Screen.ActiveControl.Name
        Case "txtTreatmentDate"
        Beep
        MsgBox "Please enter 6 digits for dates e.g. 241270 (ddmmyy)." & vbCrLf & "" & vbCrLf & _
        "Please click ok to continue.", vbInformation, "Incorrect Data Entered"
        Case "txtTreatmentTime"
        Beep
        MsgBox "Please enter 4 digits for time e.g. 2359 (HHMM)." & vbCrLf & "" & vbCrLf & _
        "Please click ok to continue.", vbInformation, "Incorrect Data Entered"
    Case Else
        msg = "Incorrect data has been entered in a field, please check and correct data"
        msg = msg & Screen.ActiveControl.Name & "!"
        End Select
        
        Response = acDataErrContinue

End If

End Sub

I can't see anything in these events that would stop the form closing with the docmd.close and believe it is written correctly..?? So i am at a total loss !!

over to the guru's !!

Thanks guys
 
Form control name? SubForm?
Are you working with a subform? Do you want to close a subform?
 
sorry may of been the way I replied but it is a 'stand alone' normal form

thanks
 

Users who are viewing this thread

Back
Top Bottom