Dirty Problem

  • Thread starter Thread starter Gel
  • Start date Start date
G

Gel

When I close a form even though it hasn't been dirtied
yet - the message box pops up. I only want it to appear
if a new record is created or Me.dirty = true.

Code in close command button:
If Me.Dirty = False And Me.NewRecord = False Then
DoCmd.CLOSE
Else

If Me.NewRecord = True Or Me.Dirty = True Then
If MsgBox("Do you want to save the change?",
vbYesNo, "Test DB") = vbYes Then
Call cmdSave_Click
Else
Me.Undo
DoCmd.CLOSE
Exit Sub
End If
Else
DoCmd.CLOSE
Exit Sub
End If
End If


Pls. help. Thanks for any advice!!!!
 
Gel said:
When I close a form even though it hasn't been dirtied
yet - the message box pops up. I only want it to appear
if a new record is created or Me.dirty = true.

Code in close command button:
If Me.Dirty = False And Me.NewRecord = False Then
DoCmd.CLOSE
Else

If Me.NewRecord = True Or Me.Dirty = True Then
If MsgBox("Do you want to save the change?",
vbYesNo, "Test DB") = vbYes Then
Call cmdSave_Click
Else
Me.Undo
DoCmd.CLOSE
Exit Sub
End If
Else
DoCmd.CLOSE
Exit Sub
End If
End If


Pls. help. Thanks for any advice!!!!

I'm not sure what logic you want to implement. This line:
If Me.NewRecord = True Or Me.Dirty = True Then

will evaluate to True if you're on a new record even if that record
hasn't been modified from its blank state. Maybe you want to say

If Me.NewRecord = True And Me.Dirty = True Then

That change, leaving the rest of the code as is, will result in the
following logic paths, if I read it right:

1. Existing record and not dirty: close form

2. Existing record and dirty: close form (saving automatically, but
without calling cmdSave_Click)

3. New record and not dirty: close form

4. New record and dirty: prompt for save and either call cmdSave_Click
and don't close, or Undo and close

I'm not sure this is what you want.
 
Gel said:
My logic is more on the latter!
Thanks for enlightening me!!!

I can't quite tell if this means your problem is now solved, or if you
have further questions. Let me know.
 
Back
Top