Kamis, 19 Mei 2011

RE: [MS_AccessPros] Excessive Privacy?

 

Myra-

Event procedures in forms are defined as Private by default so they can be
called only from other code on the form. If you change the declaration to
Public, the procedure becomes a method of the form when it's open.

I often put a Cancel button on my forms like this:

Public Sub cmdCancel_Click()
' If the form has unsaved edits
If Me.Dirty Then
' Clear the edits
Me.Undo
End If
' Close the form
DoCmd.Close acForm, Me.Name
End Sub

By making it Public, I can call it form anywhere else when the form is open. In
the Exit button of my main switchboard, I do:

Dim intI As Integer

For intI = Forms.Count - 1 To 0 Step - 1
' If this isn't the main switchboard
If Forms(intI).Name <> "frmMain" Then
' Close the form by calling its public cancel
Forms(intI).cmdCancel_Click
End If
Next intI

.. that closes all open forms by using the public cancel code that I've put in
every form.

John Viescas, author
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Microsoft Access Applications
Microsoft Office Access 2003 Inside Out
SQL Queries for Mere Mortals
http://www.viescas.com/
(Paris, France)

-----Original Message-----
From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of myrafly
Sent: Thursday, May 19, 2011 9:33 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Excessive Privacy?

John,

I'm working in word VBA. Who should I ask?

I'm trying to work around the private key word. Private functions all over the
place. I'm trying to figure out what they might have been thinking and if it's
possible to call a private sub from outside of the module.

I've never really understood the whole private public thing anyway. It just
seems excessive control freakishness. I don't get it. It must have made sense
to someone.

Thanks for pointing me in the right direction.

Myra

------------------------------------

Yahoo! Groups Links

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar