Allow edits on control in a subform (1 Viewer)

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
I'm having trouble allowing editing on a specific column on a subform. I want to allow the user access to a specific field after clicking a button. I've tried
various forms to enable the field such as

Me.subform.form.fieldx.Enabled = True
Form.formname.subform.form.fieldx.Enabled = True

I've tried all manner of things including replacing . with !

I've then tried allowing edits for the whole subform with

Me.Subform.Form.AllowEdits = True

I've tried putting the button on the sub form to no avail.
This form actually has 2 subforms and in the open event on the main form Me.secondSubform.Form.AllowEdits = True works

I can't think of what else to do
 

Cronk

Registered User.
Local time
Today, 14:45
Joined
Jul 4, 2013
Messages
2,772
If the button you are clicking on is on the parent form
Me.subform.form.fieldx.locked= false

If on the subform
me.fieldx.locked=false

If on another form
forms!formname.subform.form.fieldx.locked= false

If the 'enabled' property is false, it means the control cannot have the focus set on it, and thereby cannot be altered but it still can be locked to prevent changes..
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
If the button you are clicking on is on the parent form
Me.subform.form.fieldx.locked= false

If on the subform
me.fieldx.locked=false

If on another form
forms!formname.subform.form.fieldx.locked= false

If the 'enabled' property is false, it means the control cannot have the focus set on it, and thereby cannot be altered but it still can be locked to prevent changes..

The subform is locked (somehow). I've tried unlocking the field using enable = true and locked = false to no avail.
Pretty sure I used the format you suggest but I'll give it another go.
What did you mean by If the 'enabled' property is false, it means the control cannot have the focus set on it, and thereby cannot be altered but it still can be locked to prevent changes.. Does that mean I can't enable it?
 
Last edited:

missinglinq

AWF VIP
Local time
Today, 00:45
Joined
Jun 20, 2003
Messages
6,423
Is the errant Subform based on a Table or a Query? If a Query, especially a multi-table Query, chances are that it is simply Read-Only, as many multi-table Queries are.

Linq ;0)>
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Is the errant Subform based on a Table or a Query? If a Query, especially a multi-table Query, chances are that it is simply Read-Only, as many multi-table Queries are.

Linq ;0)>

This is where is gets spooky the record source is a select statement on 2 tables with an inner join. So I was thinking the same as you. However the errant subform is on 2 forms. One has a button that unlocks the subform without a problem. I've copied the code onto the second form and tried it and I can't get it to work. Ideally I just want to unlock 1 field on the subform .
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Plot thickens. I've changed the sub form so that if i double click on the label I've got Me.Form.AllowEdits = True so when I double click this when subform is part of form 1 it works but not if it's part of form 2
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
OK the first form is called with acFormAdd and the second with acFormReadOnly which may explain it BUT
1. can I get around the readonly in VBA code
2. The second form has 2 subforms and the 2nd form in the open event has Me.Subform2.Form.AllowAdditions = True which works
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:45
Joined
Jan 20, 2009
Messages
12,851
Sounds like the subformcontrol itself (not the form inside it) is Locked.
 

missinglinq

AWF VIP
Local time
Today, 00:45
Joined
Jun 20, 2003
Messages
6,423
Sorry, those last few posts have me totally confused...but if the Main Form that contains the errant Subform is Read-Only...its Subform will also be Read-Only! The Subform is a Subform Control, and as a Control on a Read-Only Form, it cannot be edited, which is what Access considers you to be doing if you attempt to doing anything to a Record on the Subform.

Better to Lock all Controls (except the Subform Control) on the Main Form rather than open it as Read-Only.

Linq ;0)>
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Sorry, those last few posts have me totally confused...but if the Main Form that contains the errant Subform is Read-Only...its Subform will also be Read-Only! The Subform is a Subform Control, and as a Control on a Read-Only Form, it cannot be edited, which is what Access considers you to be doing if you attempt to doing anything to a Record on the Subform.

Better to Lock all Controls (except the Subform Control) on the Main Form rather than open it as Read-Only.

Linq ;0)>

They confused me as well!
So just a recap
I want at the very least to allow edits on the sub form
When the subform is on form1 this is achieved by an event clicking a button. The code is [subform].Form.AllowEdits = True
When the subform is is on form 2 this doesn't work
The only difference I can see is that form 1 is opened
DoCmd.OpenForm "form1", , , , acFormAdd, , Me.strCLIENT
and form2 with
DoCmd.OpenForm "form2", , , "strOrderNumber='" & Me.strOrderNumber & "'", acFormReadOnly, acWindowNormal, "payment"

This any clearer
 

static

Registered User.
Local time
Today, 05:45
Joined
Nov 2, 2015
Messages
823
Either change the readonly setting of the form open, or add a button to the form to unlock the form/subform

MySubform.Form.AllowEdits = True
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Either change the readonly setting of the form open, or add a button to the form to unlock the form/subform

MySubform.Form.AllowEdits = True


see above but MySubform.Form.AllowEdits = True doesn't work

I've tried changing acFormReadOnly to acFormAdd but getting an error I don't understand on line which is basically me.x = me.y
 

static

Registered User.
Local time
Today, 05:45
Joined
Nov 2, 2015
Messages
823
me.x = me.y doesn't make any sense anyway in database terms.
 

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
me.x = me.y doesn't make any sense anyway in database terms.

I'll post it tomorrow - bed is calling me
When I call form with acFormAdd it falls over with the error I'll post tomorrow on a line that is basically
Me.control1 = me.control2
When it's called with acFormReadOnly this line works
 
Last edited:

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Error is
Run-time error 2427
You entered an expression that has no value

on this line
If Me.total = Me.Text20 Then - 2 controls on the same form

Note this fails when form is opened with acFormAdd. It works when opened with acFormReadOnly
 
Last edited:

ryetee

Registered User.
Local time
Today, 05:45
Joined
Jul 30, 2013
Messages
952
Still no idea why form 2 is giving me problems but decided to create a 3rd form with a subform to process this and now all is working.
So not solved the problem but have got round it
 

Users who are viewing this thread

Top Bottom