AllowEdits subform (continuous) based on command/toggle button- help

Asghaar

Registered User.
Local time
Today, 23:42
Joined
Jul 4, 2012
Messages
47
Hello all,

And Merry Christmas .
I have the folowing situation :
- main form L2_FtGroup_Contacts
- subform (continous,made to look like a datasheet) ,with AllowEdits NO by default - L2_FtGroup_Contacts_sub
-in the Detail section of the subform (continuous) i have a button that would like to turn on the AllowEdits property of the subform in order for the users to be able to modify or not each records.
-and one save button that saves the change and turns off the AllowEdits property of the same subform.

Although I've tried a lot of combinations can't seem to be able to make the first button turn on the property for the subform.
Could you please help me?

Below some alternatives tried on the on click event of the togle/command button:

Code:
'Me.L2_FtGroup_Contacts_sub.Form.AllowEdits = True
'Forms!L2_FtGroup_Contacts!L2_FtGroup_Contacts_sub!Form.AllowEdits = True
'Me!L2_FtGroup_Contacts_sub.Form.AllowEdits = True
'L2_FtGroup_Contacts.Form.AllowEdits = True
'Forms!L2_FtGroup_Contacts!L2_FtGroup_Contacts_sub.AllowEdits = False

'If Me.OpenArgs = "Edit" Then
'Me.frmSubForm.Form.AllowAdditions = True
'Me.L2_FtGroup_Contacts.L2_FtGroup_Contacts_sub.Form.AllowEdits = True
'Me.frmSubForm.Form.AllowDeletions = True

'If Me.AllowEdits = True Then
'Me.AllowEdits = False
'Forms![L2_FtGroup_Contacts]!L2_FtGroup_Contacts_sub.AllowAdditions = True
'Else
'Me.AllowEdits = True
'Me.Toggle35.Caption = "Edit On"
'End If

For any of the combinations above when i press it nothing happens and can't edit the fileds.
If I do it manually - properties and set the Allow Edits to Yes.. works.

Thank you.

Kind regards,
 
- subform (continous,made to look like a datasheet) ....
-in the Detail section of the subform (continuous) i have a button ....
Hmm - how can you have a button showed in a datasheet form?
 
Hello,

As i Stated is a continuous form ( only made to loo like a dataheet) - so the form is continuous.
Hopethis clears things a little.

Regards,
 
Last edited:
Ok - then use a Button control instead as a Toggle control.
You can't change a Toggle control, when you have set AllowEdits to False.
 
Hi,

Thank you managed to make it work (cmd button) with the following code
Code:
[Forms]![L2_FtGroup_Contacts]![L2_FtGroup_Contacts_sub].Form.AllowEdits = True

So i've added another button to stop the editing with this code
Code:
[Forms]![L2_FtGroup_Contacts]![L2_FtGroup_Contacts_sub].Form.AllowEdits = False

But it seems that the second button is not working,the AllowEdits remains on True and doesnt get back switched to False as it should.

Can you advise why is this?

Regards,
===

So,i think i figure it out
It seems i need to requery the subform in order to see the current AllowEdits status,aka True.
When i insert a requery command askes for the record to be saved , so :
Here is my save button:)
Code:
oCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Forms![L2_FtGroup_Contacts]![L2_FtGroup_Contacts_sub].Requery
    [Forms]![L2_FtGroup_Contacts]![L2_FtGroup_Contacts_sub].Form.AllowEdits = False

Still don;t understand completely why it needs a requery in order to take the false command, but i'm glad it works.

Thank you for the help.
 
Last edited:
Are you sure the Click event for that button got fired, put in a break point in the code?

Why are you not using "Me.Form.AllowEdits" instead of "[Forms]![L2_FtGroup_Contacts]![L2_FtGroup_Contacts_sub].Form.AllowEdits"?

If you use "Me.Form.AllowEdits = Not Me.Form.AllowEdits" then you only need 1 button.
 
I think the following code can do it.:)
Code:
  If Me.Form.AllowEdits Then
    Me.Form.Recalc
  End If
  Me.Form.AllowEdits = Not Me.Form.AllowEdits
 
Hi,
And it does.
Thank you very much works great.
I wish you all the best and a Happy new Year .

The reason why i used why i used is simple,didn't know other way - i'm kinda a self learner when it comes to VBA/Access.

Regards,

====
Small question : If i want to inset a caption changer in your code how could i do that ?
I mean to write "Edit on" when is true and "Edit off" when False

Code:
 Me.Command44.Caption = "Edit Off"
 
Last edited:
You're welcome and also Happy New Year to you.

Yes I know in the start it can be a very steep learning curve. :D
Give your buttons and controls reportedly names, otherwise you'll in about 2 weeks not remember what Command44 is or does. :) :)
A good name = "EditOnOff"

Code:
If Me.Form.AllowEdits Then
    Me.Form.Recalc
    Me.ActiveControl.Caption = "Edit Off"
  Else
    Me.ActiveControl.Caption = "Edit On"
  End If
  Me.Form.AllowEdits = Not Me.Form.AllowEdits
 
I think the following code can do it.:)
Code:
  If Me.Form.AllowEdits Then
    Me.Form.Recalc
  End If
  Me.Form.AllowEdits = Not Me.Form.AllowEdits


Hello,

This is amlost exactly what need, but is there a way to put it into a functin/macro so I can use it from a menu?

Thanks!
 
Put the following code into a module, (remember to change "YourFormName" to the name of your form):

Code:
Sub EditNotEdit()
  If Forms![YourFormName].Form.AllowEdits Then
    Forms![YourFormName].Form.Recalc
  End If
  Forms![YourFormName].Form.AllowEdits = Not Forms![YourFormName].Form.AllowEdits
End Sub

To call the sub use: Call EditNotEdit
 
I have a follow up question for this solution.

I have a listbox on the form that I am calling the editnotedit sub for and when a user clicks on one of the items in it, it will load that record in another form. the list box is also locked and I do not want it to be. Is there a way to keep that listbox usable?

thank you..

Paul
 
...the list box is also locked and I do not want it to be. Is there a way to keep that listbox usable?
Could you explain, what do you mean with locked and usable?
How do you want it to be?
 
The listbox has code on the doubleclick event that loads the selected record. I am not able to doubleclick on it when the form is locked for editing. When I hit the button to 'edit' the form, I can doubleclick on the listbox again.

I would like to be able to doubleclick on the listbox items even when the form is not in edit mode.

Hope this helps.

Thanks.
 
Try the following:
Code:
Private Sub YourListName_Enter()
  Me.AllowEdits = True
End Sub

Private Sub YourListName_Exit(Cancel As Integer)
  Me.AllowEdits = False
End Sub
 

Users who are viewing this thread

Back
Top Bottom