Close Form without Saving Dirty Form?

BubbaBBQ

Board Regular
Joined
Jan 29, 2003
Messages
68
The form has two buttons. They are "Close" and "Save". If the form has had information added, but should not be saved, I want the user to be able to click on close and the form go away without adding a record. (Currently it adds the record.) Here is the code and you can see the attempts that I have made.

Do y'all have any suggestions?

Bubba

Code:
Private Sub Form_Load()
    DoCmd.GoToRecord , , acNewRec
  Provider_number.SetFocus
End Sub

Private Sub Save_Click()

On Error GoTo Err_Save_Click

Dim vPTestOK As Integer
Dim vSave As Boolean
vPTestOK = 1
vSave = True

If IsNull(Provider_number) Then
    vPTestOK = MsgBox("Missing Provider Number!  Save?", vbOKCancel, "PAC Track")
    
    If vPTestOK = 1 Then
        vSave = True 'Save regardless
    Else
        vSave = False 'Do not save record
    End If
End If

If vSave = True Then
    Me!Time = Time
    DoCmd.GoToRecord , , acNewRec
    GoTo Exit_Save_Click
Else
    GoTo Exit_Save_Click
End If

Exit_Save_Click:
    Provider_number.SetFocus
    Exit Sub

Err_Save_Click:
    MsgBox Err.Description
    Resume Exit_Save_Click
    
End Sub

Private Sub Close_Click()
On Error GoTo Err_Close_Click
   
    DoCmd.Close , , acSaveNo
    'DoCmd.Quit (acQuitSaveNone)
    'DoCmd.Quit acQuitSaveNone
    
Exit_Close_Click:
    Exit Sub

Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,221,537
Messages
6,160,401
Members
451,645
Latest member
hglymph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top