close and reset view

SueBK

Registered User.
Local time
Today, 13:31
Joined
Apr 2, 2009
Messages
197
I have a form, let's call it "Risks". On the form view there is a command button. It opens the same form but in datasheet view and filtered against certain criteria.

I would like to create an "on close" command for the form that says "if this form is in datasheet view and is closed, then actually don't close it, but re-set the view to form view".

Is it possible?
 
If Me.CurrentView = 2 then
Me.CurrentView = 1
Else: DoCmd.Close
End If
 
Try the following on you on close event;

Code:
If Me.CurrentView = 2 Then[COLOR="SeaGreen"] ' 0 = Design view, 1 = Form View, 2 = DatasheetView[/COLOR]
     DoCmd.OpenForm "Frm_Name", acNormal
     Exit Sub
End if
 
Sorry just been playing, you will need to put my code on a button that closes the form, as you can't change the form view during the OnClose event.
 
If Me.CurrentView = 2 then
Me.CurrentView = 1
Else: DoCmd.Close
End If

Sorry Me.CurrentView only allows you to determine the current form view, it does not allow you to force changes of the current form view, that must be done using the DoCmd.OpenForm command.
 
So, really, the easiest way is to copy my form and call it "Risk2" or something? 'Cause the datasheet view can't have command buttons.
 
You could embed your Form Risk in an unbound Main form, on which you could have your control buttons. These buttons could then control the view of your From Risk.
 
The code would look something like;

Code:
    If Forms!FRM_Main!FRM_SubForm.Form.CurrentView = 2 Then [COLOR="Green"]' 0 = Design view, 1 = Form View, 2 = DatasheetView[/COLOR]
        Me.FRM_SubForm.SetFocus
        DoCmd.RunCommand acCmdSubformFormView
        Exit Sub
    End If

    DoCmd.Close
 
Last edited:

Users who are viewing this thread

Back
Top Bottom