Solved Error 2447

Can you lock a form?

I thought you could only lock controls, but don't have Windows open to check
Well despite the editor propering the command
Me.Locked = True

I get 'Method or data member not found'
 
You are trying to set the .Locked property on a [sub]Form object which does not have that property.

What are you trying to do?
 
First things to check:

1. The main form is called "Dispatch" ?

2. The main form has a subform CONTROL named "frmLoadsBillingSubform" (not just a subform with SourceObject = "frmLoadsBillingSubform") ?

3. In which form's module is the Form_Current event running?
 
You can lock the subform control by removing the .form. Not the form in the subform control.
 
First things to check:

1. The main form is called "Dispatch" ?

2. The main form has a subform CONTROL named "frmLoadsBillingSubform" (not just a subform with SourceObject = "frmLoadsBillingSubform") ?

3. In which form's module is the Form_Current event running?
Hi David

It is in the OnCurrent of the Subform frmLoadsBillingSubform

I have removed all code from the Current Event and am starting from scratch.

There are currently no Errors when I open the Form
 
Hi David

It is in the OnCurrent of the Subform frmLoadsBillingSubform

I have removed all code from the Current Event and am starting from scratch.

There are currently no Errors when I open the Form
So if the code is in the subform you want to lock, why the full naming reference of the form and not Me. ?

Plus your subform control name is the same as your formname, which will likely be confusing?
 
So if the code is in the subform you want to lock, why the full naming reference of the form and not Me. ?

Plus your subform control name is the same as your formname, which will likely be confusing?
Hi Gasman

OK I tried this Code

Code:
Private Sub Form_Current()

If Me.txtStatus = "Billed" Then

Me.frmLoadsBillingSubform.Locked = True

Else

Me.frmLoadsBillingSubform.Locked = False

End If
I get the following error.
 

Attachments

  • Error.PNG
    Error.PNG
    6 KB · Views: 98
Again, if that is in the subform there is no frmLoadsBillingSubform :(

You are IN frmLoadsBillingSubform

Plus I thought you have been told there is no Lock property for a form?
 
It is in the OnCurrent of the Subform frmLoadsBillingSubform
OK. So you probably don't need to refer to the main form by name

Still, did you double check that the name of the subform control that houses the [sub]form frmLoadsBillingSubform is also called "frmLoadsBillingSubform" - it may be called something like "Child0"

In the Current event of frmLoadsBillingSubform you can have code like:

Code:
Private Sub Form_Current()

  Me.Parent.frmLoadsBillingSubform.Locked = Me.txtStatus = "Billed"

End If

BUT only if the subform CONTROL on the main form is named "frmLoadsBillingSubform"
 
OK. So you probably don't need to refer to the main form by name

Still, did you double check that the name of the subform control that houses the [sub]form frmLoadsBillingSubform is also called "frmLoadsBillingSubform" - it may be called something like "Child0"

In the Current event of frmLoadsBillingSubform you can have code like:

Code:
Private Sub Form_Current()

  Me.Parent.frmLoadsBillingSubform.Locked = Me.txtStatus = "Billed"

End If

BUT only if the subform CONTROL on the main form is named "frmLoadsBillingSubform"
Hi David

Looks like this is a nono.

I tried the following

Code:
Private Sub Form_Current()

Me.Parent.frmLoadsBillingSubform.Locked = Me.txtStatus = "Billed"


End Sub
And we are back to the Error 2447 again
 
Still, did you double check that the name of the subform control that houses the [sub]form frmLoadsBillingSubform is also called "frmLoadsBillingSubform" - it may be called something like "Child0"
You still haven't confirmed that you are referring to the correct objects.

If you don't know what I mean then ask.

Also, is txtStatus a control on the subform or mainform?
 
You still haven't confirmed that you are referring to the correct objects.

If you don't know what I mean then ask.

Also, is txtStatus a control on the subform or mainform?
Hi David
My apologies, Yes the Subform Cointrol is named "frmLoadsBillingSubform"
The txtStatus is a Control on the Subform
 
Might be quicker all round if you just upload enough of the db to see the error?
 
Hi Gasman

Here with a stripped down db

In the Form Dispatch that opens on start if you select Load Nr 133876 the Billing Subform contains data.

If you change the Status from Available to Billed we need the Controls on the Billed Subform to be Locked.

Any help appreciated
 

Attachments

The problem seems to be that Access is confused because the name of the subform control and the form used as its SourceObject are the same.

I changed the name of the subform control in form Dispatch to "sfLoadsBills". Then I put the following code in the Current event of form frmLoadsBillingsSubform:
Code:
Private Sub Form_Current()
  With Me
    .Parent.sfLoadsBills.Locked = Nz(.txtStatus, vbNullString) = "Billed"
  End With
End Sub
Seems to work for me.
 
The problem seems to be that Access is confused because the name of the subform control and the form used as its SourceObject are the same.

I changed the name of the subform control in form Dispatch to "sfLoadsBills". Then I put the following code in the Current event of form frmLoadsBillingsSubform:
Code:
Private Sub Form_Current()
  With Me
    .Parent.sfLoadsBills.Locked = Nz(.txtStatus, vbNullString) = "Billed"
  End With
End Sub
Seems to work for me.
Probably why I name my subform controls differently. :)

Just got in and having a look?

Confused as to why you are using the subform current event for when the status in the mainform changes?, would that not be the main form current event? or afterupdate event of the mainform txtstatus control?
While you now have a better method to lock the controls, this worked for me in the subform current event.

Code:
Private Sub Form_Current()
Debug.Print "Subform current " & Me.cboRateType.Enabled
Debug.Print Me.txtStatus
Me.cboRateType.Enabled = Nz(Me.txtStatus, "") <> "Billed"
End Sub

I too changed the subform control name.

However on the first run I get the error below on line

Debug.Print Me.txtStatus

which might be because you set the subform txtstatus to the mainform txtstatus, yet the mainform has not even loaded? :(
1673462243295.png
 
Last edited:
Hi Everyone

I finally got a solution by using an OnClick event on a Command Button as follows that does what I need.

Code:
Private Sub cmdDisable_Click()
Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox) Then
        ctrl.Enabled = False
    End If
Next

End Sub

Many thanks for all who contributed.
 

Users who are viewing this thread

Back
Top Bottom