Form wont close.

  • Thread starter Thread starter MartinR
  • Start date Start date
M

MartinR

I want the form to close automatically after the record has been
deleted. An info message appears after the deletion of the record, "no
curret record", that is why i have the error code to avoid this being
shown. But the form does not close, but instead displays a blank
record.
Can someone please help with my problem,thanks


Private Sub Back_Click()
On Error GoTo Err_Back_Click


Const MB_OK = 0, MB_OKCANCEL = 1 ' Define buttons.
Const MB_YESNOCANCEL = 3, MB_YESNO = 4
Const MB_ICONSTOP = 16, MB_ICONQUESTION = 32 ' Define icons.
Const MB_ICONEXCLAMATION = 48, MB_ICONINFORMATION = 64
Const MB_DEFBUTTON2 = 0, IDYES = 6, IDNO = 7 ' Define other.


Title = "Exit without adding image"
DgDef = MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2
Response = MsgBox("Are you sure you want to exit without adding
an image?", DgDef, Title)


If Response = IDYES Then


DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.Close acForm, Me.Name
DoCmd.SetWarnings True
Else


End If


Exit_Back_Click:
Exit Sub


Err_Back_Click:
If Err.Number <> 3021 Then
MsgBox Err.Description
End If
Resume Exit_Back_Click


End Sub
 
Private Sub Back_Click()
On Error GoTo Err_Back_Click
Title = "Exit without adding image"
DgDef = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox("Are you sure you want to exit without adding an
image?", DgDef, Title)

If Response = vbYes Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If

CloseAnyway:
DoCmd.Close acForm, Me.Name

Exit_Back_Click:
Exit Sub

Err_Back_Click:
If Err.Number <> 3021 Then
MsgBox Err.Description
Resume CloseAnyway
Else
Resume Exit_Back_Click
End If
End Sub
 
I copied your code exactly, but the form still won't close after i
click yes in the message box. It still displays a blank record in the
form. It appears to be not doing anything after the close form line. Is
there another way around it?
 
In the code press F9 on the first line.
This creates a break point.
When you execute the code it stops on that line.
You can then press F8 to single-step through the code, and see where it is
going and why the Close line is not executing.
 
I used that method and i saw the way the path of the code went. It
didn't go back up to the right spot after it went through the error
part, so i rearranged its path and i got to to go the correct way. The
problem was simple in the end. heres the final code that works:

Private Sub Back_Click()
On Error GoTo Err_Back_Click

Title = "Exit without adding image"
DgDef = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox("Are you sure you want to exit without adding an
image?", DgDef, Title)

If Response = vbYes Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
CloseAnyway:
DoCmd.SetWarnings True
DoCmd.Close acForm, Me.Name
End If

Exit_Back_Click:
Exit Sub


Err_Back_Click:
If Err.Number <> 3021 Then
MsgBox Err.Description
Resume Exit_Back_Click
Else
Resume CloseAnyway

End If
End Sub

Thanks for your help with the problem, i wouldn't have figured it out
without it, Cheers
 

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

Back
Top