Stuart McLachlan
stuart at lexacorp.com.pg
Thu Aug 26 16:41:13 CDT 2010
Set the visible state in the on_open as well Simple test case:
Private Sub Form_Open(Cancel As Integer)
Me.Visible = False
If MsgBox("Show the form", vbOKCancel) <> vbOK Then
Cancel = True
Else
Me.Visible = True
End If
End Sub
On 26 Aug 2010 at 17:23, jwcolby wrote:
> But there are many ways to open a form and I would prefer to not have
> the security work only if opened through this method.
>
> John W. Colby
> www.ColbyConsulting.com
>
>
> Heenan, Lambert wrote:
> > Like Drew said...
> >
> > Using an OpenAgs value to simulate your security check, just open
> > the form acHidden
> >
> > Sub testFormOpen(strArgument As String)
> > On Error GoTo testFomrOpen_Error
> > DoCmd.OpenForm "form2", , , , , acHidden, IIf(strArgument > " ",
> > strArgument, Null) Debug.Print IsLoaded("form2")
> > testFomrOpen_Exit:
> > On Error GoTo 0
> > Exit Sub
> >
> > testFomrOpen_Error:
> > Select Case Err.Number
> > Case 2501 ' For open cancelled
> > ' do nothing
> > Resume Next
> > Case Else
> >
> > Debug.Print Err.Number, Err.Description
> > Resume testFomrOpen_Exit
> > Resume Next
> > End Select
> >
> > End Sub
> >
> > And then in the Open event of the form...
> >
> > If OpenArgs & "" > "" Then <== If YourSecurityCheckPassed
> > Me.Visible = True
> > Else
> > Cancel = True
> > End If
> >
> >
> > Lambert
> >
> > -----Original Message-----
> > From: accessd-bounces at databaseadvisors.com
> > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
> > Sent: Thursday, August 26, 2010 4:00 PM To: Access Developers
> > discussion and problem solving Subject: [AccessD] Prevent displaying
> > a form until...
> >
> > I am starting to test my table driven Presentation Level Security
> > system. I have a login etc. When a form opens, in the OnOpen I
> > initialize an instance of the class that will drive the security for
> > that form. I do it there because I can set Cancel = true to force
> > the form to shut back down if the user is not allowed to use the
> > form.
> >
> > The problem is that the form *displays* even if it eventually shuts
> > back down.
> >
> > This is an issue because I pop up a message box saying that the user
> > is not allowed to open the form, but it is already open and
> > displaying data behind the message box. Oooops.
> >
> > The only other time I have addressed this issue I opened a dummy
> > form in front of the form being opened so that the form actually
> > being opened was hidden. That is an ugly solution to a common
> > problem.
> >
> > Has anyone solved this problem in an elegant fashion.
> >
> > --
> > John W. Colby
> > www.ColbyConsulting.com
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>