Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Access 2000 - AllowEdits property - setting false disables change of button.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David W. Fenton  
View profile  
 More options Jan 2 2003, 3:33 pm
Newsgroups: comp.databases.ms-access
From: dXXXfen...@bway.net (David W. Fenton)
Date: Thu, 02 Jan 2003 20:28:20 GMT
Local: Thurs, Jan 2 2003 3:28 pm
Subject: Re: Access 2000 - AllowEdits property - setting false disables change of button.
No Spam Please (Tester) wrote in
<3e147d9...@news1.homechoice.co.uk>:

>Therefore this combo box has the key field assocaited with it and
>list each record in the table. I have to set the onfocus event to
>set allowedits to be true, and then the lost focus, to the current
>setting of the edit lock command button.

>I can think of no other way of doing this when using the Allowedit
>form property.

I never use AllowEdits because it means that even unbound combo
boxes (used for finding records) are not enabled.

I always create a custom collection of all the bound controls in
the form's OnOpen event, and then set controls to locked/unlocked
when needed by looping through the custom collection.

It would work something like this:

In the OnLoad event of the form:

  Call InitializeCollections

That sub looks like this:

  Private Sub InitializeCollection()
    Dim ctl As Control

    If (mcolFields Is Nothing) Then
       Set mcolFields = New Collection
       For Each ctl In Me.Controls
         If ctl.Tag = "Bound" Then
            mcolFields.Add ctl, ctl.Name
         End If
       Next ctl
    End If
    Set ctl = Nothing
  End Sub

All it does is create a collection of all the editable controls.

Assuming the controls are saved in a locked state, you need to
nothing further in the OnLoad.

For your EDIT button, it would be something like this:

  Call SetEdit

That sub would look something like this:

  Public Sub SetEdit()
    Dim ctl As Control
    Dim varCtl As Variant

    InitializeCollection
    For Each varCtl In mcolFields
       Set ctl = varCtl
       ctl.Locked = Not ctl.Locked
    Next varCtl

    If (ctl.Locked) Then
       Me.Dirty = False
       Me!btnEdit.Caption = "Edit"
    Else
       Me!btnEdit.Caption = "Save"
    End If

    Set ctl = Nothing
  End Sub

Now, I'm not sure I would use Edit/Save as my captions for the
button, but you get the idea (i.e., "Save" implies that it is only
saved when you click the button, whereas any number of operations
actually might force a save to the underlying data table).

Also, if your form loads more than one record (something I wouldn't
necessarily recommend in this kind of context) you'll have to
determine what should happen if the user departs a record without
hitting the SAVE button. The easiest approach is to have the
OnCurrent set the command button's caption to "Edit" and then call
your SetEdit() sub.

Personally, I've hardly ever implemented anything like this for
editing (I do lots of custom collections, and also locking of
controls on forms) because it really only works in a fully unbound
form. My personal preference is that all fields should be editable
as soon as a record is loaded *if* the user should be allowed to
edit this particular record. I see no point with a bound form of
trying to work inconsistently around the behaviors of bound forms
-- you'll only be implying things that you can't really do (such as
cancelling edits, etc.).

I really can't conceive of a situation where you'd really want to
disable editing of controls with a command button if the form is
bound.

--
David W. Fenton                        http://www.bway.net/~dfenton
dfenton at bway dot net                http://www.bway.net/~dfassoc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.