Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

new record event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roland Alden - 10 Mar 2005 01:08 GMT
I have some controls in a form locked because changing them is uncommon (the
name fields in a record) and it's sort of easy to accidently edit them. I
have a little button the user can hit if they really want to be able to edit
them but this is off by default.

However, when the user hits the new record * in the navigation I want to
unlock these controls until the point where they save the record at which
point I'd like to go back to the locked state. I am guessing the After
Insert event would work for the latter but I'm not sure about the former.
Before Insert? On Load?
Douglas J. Steele - 10 Mar 2005 01:16 GMT
The Current event fires when you move to a new record.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I have some controls in a form locked because changing them is uncommon
>(the
[quoted text clipped - 8 lines]
> Insert event would work for the latter but I'm not sure about the former.
> Before Insert? On Load?
Arvin Meyer - 10 Mar 2005 01:25 GMT
Here's some code to put in a standard module to Lock all the controls. To
change all of them to unlocked, write a new function with ctl.Locked set to
False:

Public Sub LockControls(frm As Form)
On Error Resume Next
Dim ctl As Control

   For Each ctl In frm.Controls
       With ctl

           Select Case .ControlType
               Case acTextBox
                   ctl.Locked = True

               Case acComboBox
                   ctl.Locked = True

               Case acListBox
                   ctl.Locked = True

               Case acCheckBox
                   ctl.Locked = True

               Case acToggleButton
                   ctl.Locked = True

               Case acSubform
                   ctl.Locked = True

               Case acOptionGroup
                   ctl.Locked = True

               Case acOptionButton
                   ctl.Locked = True

           End Select
       End With
   Next ctl
   Set ctl = Nothing
   Set frm = Nothing

End Sub

Then use a bit of code like this in the form's Current event (aircode):

Sub Form_Current()

If Me.NewRecord = True Then
   UnlockControls(Me)
Else
   LockControls(Me)
End If

End Sub
Signature

Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

> I have some controls in a form locked because changing them is uncommon (the
> name fields in a record) and it's sort of easy to accidently edit them. I
[quoted text clipped - 6 lines]
> Insert event would work for the latter but I'm not sure about the former.
> Before Insert? On Load?
Roland Alden - 10 Mar 2005 03:07 GMT
Thanks very much. It was the Me.NewRecord field that I was searching for.
Perfect.

I was wondering about the case statement in the loop that visits every
control. I gather it is necessary to hit only certain types of controls?
What would happen if you just did this:

For Each ctl In frm.Controls
   ctl.Locked = True
Next ctl

If I want to remember the preferred state of each control where is the best
place to store that? Is there am (easy) way to attach some data to each
control?
Arvin Meyer - 10 Mar 2005 03:18 GMT
Answers in line:

> Thanks very much. It was the Me.NewRecord field that I was searching for.
> Perfect.
[quoted text clipped - 6 lines]
>     ctl.Locked = True
> Next ctl

Some controls, like command buttons and tab controls don't have a locked
property. You could just ignore the error (like my code does) and go on, but
I also use a version of that code to disable controls and to read the Tag
property for different actions.

> If I want to remember the preferred state of each control where is the best
> place to store that? Is there am (easy) way to attach some data to each
> control?

You can set the state in the property sheet and the form will open with
those values. Setting the recordsource of the form to a table, query, or sql
string, and then binding the controls to fields will attach data  to each
control by records. To set "values" to accomplish certain actions, you can
use the TAG property.
Signature

Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Roland Alden - 10 Mar 2005 04:49 GMT
Ah, the tag property. Just what I was looking for. Thank you.

Now, one other question. I see that subforms have a Locked property that is
apparently forced on the underlying form. This is nice because it means you
don't have to do a "deep walk" of the whole tree to lock all the controls.
However, I do like to set the background color of locked controls so the
user has a visual cue. I could probably put some general code in each
subform's current to walk the controls and color them or some such.

But my real question is why am I walking the top level form at all? Can I
just set the top level forms' Locked to true?

If a subform object on the top level has a Locked property is there some way
to access its state from the underlying subform?
Arvin Meyer - 11 Mar 2005 12:26 GMT
In Access, a subform is a control, like a textbox, until it has focus. Then
it becomes a form.

The locked property is a control property, not a form property. Controls
have a Parent property. The parent of a subform is a form. So you can
traverse up and down the levels, but you can only lock controls, not forms.
(I hope that makes some sense)

Forms can have their editing attributes disabled.
Signature

Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

> Ah, the tag property. Just what I was looking for. Thank you.
>
[quoted text clipped - 10 lines]
> If a subform object on the top level has a Locked property is there some way
> to access its state from the underlying subform?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.