run-time error 2166 - can't lock control ???

Joined
Jan 11, 2008
Messages
1
Reaction score
0
I have an Unbound Form that I am using to generate copies of an existing Inventory record and then insert them into the db. The form has a number of controls that are initially populated with data from the db item to be copied (referenced from another form).

I am trying to allow the user to change some of the data (modifiable fields via unbound form controls) but to LOCK the controls for the data fields that the user is NOT allowed to edit. Also, I want to LOCK the modifiable field controls UNTIL the user has entered data in a few new required fields (QTY and Starting #). These required fields allow the user to select the starting InventoryControl number and quantity of copies. Whenever either of these 2 values is changed, the "proposed" InventoryControl numbers need to be checked to make sure they are not already in the database. Until that check has been done, I need to lock the modifiable field controls. At any point, the user can change either the QTY or Starting # in which case, I need to clear any changes to modifiable fields and lock things down.

I am using the control.Locked property to do this. However, I am receiving run-time error 2166 [You can't lock a control while it has unsaved changes] when trying to lock the controls - even though the data in the controls has NOT been changed. This ONLY occurs AFTER the modifiable controls have been UNLOCKED and then the user resets one of the required fields which means I need to lock the controls until the new required data is validated. See the DisableModifiableDataControls() sub.

As mentioned, the form and the controls are unbound, so I can't use the DIRTY property. I have added global boolean variables to monitor the "changed" status of the fields. In each modifiable control's Change event, I set the associated changed global boolean to true.

I have included some code snippets.

I hope someone can help me figure this out.
Thanks


Code Snippets:

Private Sub DisableModifiableDataControls()
' Clear via Undo, and Lock controls

***** Prior to ERROR, this global is FALSE ******
If (bGlobalDivisionChanged = True) Then
Me.ComboDivisions.Undo
bGlobalDivisionChanged = False
End If

If (bGlobalPurchaseDateChanged) Then
Me.txtPurchasePrice.Undo
bGlobalPurchaseDateChanged = False
End If

***** RUNTIME ERROR 2166 OCCURS HERE ******
***** even though ComboDivisions has NOT changed ******
Me.ComboDivisions.Locked = True
****************************************
Me.txtPurchaseDate.Locked = True
Me.txtPurchasePrice.Locked = True
End Sub


' Set global on change
Private Sub ComboDivisions_Change()
bGlobalDivisionChanged = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top