mamradzelvy
Member
- Local time
 - Today, 06:01
 
- Joined
 - Apr 14, 2020
 
- Messages
 - 145
 
Hello,
I got this neat little thing somebody offered as a solution a while ago to a problem i had.
It's a "do you want to save changes?" type prompt, however, on selecting "no" it always results in an error, what's wrong with it?
the error is being caused by the docmd.close line apparently and error is 2501
	
	
	
		
 I got this neat little thing somebody offered as a solution a while ago to a problem i had.
It's a "do you want to save changes?" type prompt, however, on selecting "no" it always results in an error, what's wrong with it?
the error is being caused by the docmd.close line apparently and error is 2501
		Code:
	
	
	Private Sub Form_BeforeUpdate(Cancel As Integer)
 Dim Answer As Integer
 If Me.Dirty = True Then
    Dim Response As Integer
    ' Displays a message box with the yes and no options.
    Response = MsgBox(Prompt:="Přejete si uložit data?", Buttons:=vbYesNo)
    ' If statement to check if the yes button was selected.
    If Response = vbNo Then
        DoCmd.RunCommand acCmdUndo
        DoCmd.Close
    End If
 Else
    ' The yes button was selected.
    DoCmd.Close
    Globals.Logging "Zapujceni"
  End If
End Sub