Control Locking in datasheet view

irish634

Registered User.
Local time
Today, 17:14
Joined
Sep 22, 2008
Messages
230
Hi everyone,

I was wondering if I can solicit some ideas because I am sure I am going about this incorrectly.

I have a subform in a form. The subform is in datasheet view.

In the "Form_Current" routine, I am trying to lock the controls if a record exists, but unlock the controls if it is a new record.

Here is what I have:
Code:
    Dim frm as Form
    Dim ctl As Control
    Set frm = Me.Form
    If Me.NewRecord = True Then
        For Each ctl In frm
            ctl.Locked = False
        Next
    Else
         For Each ctl In frm
             ctl.Locked = False
        Next
    End If
    Set frm = Nothing
When I get to the records, I get this error:
"Runtime error '438':"
"Object doesn't support this property or method"

It's referring to the "ctl.locked =" statement.

If I call each control by name, the code works like a charm
Ex:
Code:
    If Me.NewRecord = True Then
        txt_AcquisitionType.Locked = False
        txt_AcquisitionDesc.Locked = False
    Else
        txt_AcquisitionType.Locked = True
        txt_AcquisitionDesc.Locked = True
    End If
Calling each control by name is fine on the smaller forms, but I have a subform with many controls and if possible I just want to use a blanket statement and loop through the controls instead of naming each of them.

Anyone have any ideas or can point me in the right direction?

Thanks,
Craig
 
My guess is that you're hitting a control that doesn't have a locked property (a label for instance). You might add a test:

Code:
    Select Case ctl.ControlType
      Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
 
My guess is that you're hitting a control that doesn't have a locked property (a label for instance). You might add a test:

Code:
    Select Case ctl.ControlType
      Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox

Ahh yes.... I should have caught that. DOH!! :o
Thank you.
 
This might be a dumb suggestion but can't you achieve this by setting the subform properties Allow Edits to no and Allow Additions to yes?
 
Absolutely; I was trying to address why the code failed.
 
This might be a dumb suggestion but can't you achieve this by setting the subform properties Allow Edits to no and Allow Additions to yes?

Absolutely. That would be my preference. But I have an ulterior motive for doing it this way. I am unlocking the record for editing in the double-click event. That way admins can edit incorrect fields.

Thanks again Paul.

Craig
 
So why not toggle the Allow Edits property?
 

Users who are viewing this thread

Back
Top Bottom