Trying to close a form without saving data

goodfu

Registered User.
Local time
Today, 18:24
Joined
Dec 23, 2010
Messages
140
I have a form "frmMainMenu" with menu items on it. When I click on an item, before opening a form the following code is executed to close open forms.

Code:
Dim frm as Form
    For icount = 1 To Forms.Count + 1
        For Each frm In Forms
            If frm.Name <> "frmMainmenu" Then
                DoCmd.Close acForm, frm.Name
            End If
        Next frm
    Next icount

The problem I have is that if an entry has been made into a form, the record is saved. I don't want that as I have an explicit save on the form. Is there some way to close a form without saving the data when closing it from another form? I tried putting Me.Undo in the On Close event of the form being closed and that didn't work. I just need it not to save that record, either by putting something in the form or modifying the above code.
 
Welcome to the forum.

Try the following;
Code:
Dim frm as Form
    For icount = 1 To Forms.Count + 1
        For Each frm In Forms
            If frm.Name <> "frmMainmenu" Then
                [B][COLOR="Purple"]frm.Name.Dirty = False[/COLOR][/B] [COLOR="Green"]'Dirty = false will undo any changes[/COLOR]
                DoCmd.Close acForm, frm.Name
            End If
        Next frm
    Next icount
 
I get an error message "Invalid qualifier" and it highlights frm.Name.Dirty.
 
Sorry that code should have read;

Code:
Dim frm as Form
    For icount = 1 To Forms.Count + 1
        For Each frm In Forms
            If frm.Name <> "frmMainmenu" Then
                [B]Forms![/B]frm.Name.Dirty = False 'Dirty = false will undo any changes
                DoCmd.Close acForm, frm.Name
            End If
        Next frm
    Next icount

However the problem is as soon as the focus shifts to another form any changes made to data in that form are saved. So the code I've suggested will not work.
 
How about always cancelling the update in BeforeUpdate, UNLESS it is committed by your explicit save?
 
Me.Undo
DoCmd.Close

just paste that into a button code.
 
eg :


Dim frm as Form
For icount = 1 To Forms.Count + 1
For Each frm In Forms
If frm.Name <> "frmMainmenu" Then
Me.Undo
DoCmd.Close acForm, frm.Name
End If
Next frm
Next icount
 
eg :


Dim frm as Form
For icount = 1 To Forms.Count + 1
For Each frm In Forms
If frm.Name <> "frmMainmenu" Then
Me.Undo
DoCmd.Close acForm, frm.Name
End If
Next frm
Next icount
Should be frm.Undo
 
sorry - forgot you were trying to close other forms not the one your on. good call vbainet
 

Users who are viewing this thread

Back
Top Bottom