Access 2003 Error 2166 unsaved changes trying to set locked in unbound form and control

Hi all,

I'm trying to lock an unbound control (textbox) on an unbound form and getting the error 2166 ("You can't lock a control while it has unsaved changes").

I am clearing the textbox (in VBA code) before attempting to set .Locked = True

Of course the .Dirty does not function like a bound form, what is the VBA work-around for this error in a case like this?

Bill in Ottawa

In what event are you running this code? Try the <control>_AfterUpdate event.
-Tom.
Microsoft Access MVP
Phoenix, AZ

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Tom,
I have a combobox (ComboGroup) whose OnChange calls a function (SetParametersEnabled) where in you find this code ... (The error only occurs when llTrueOrFalse is 'True')

With [Forms]![Export To Excel Preselection Screen]

            !txtBeginYearFrom = ""
            !txtBeginYearTo = ""
            !txtFiscalYearFrom = ""
            !txtFiscalYearTo = ""
            !txtFYEndDateFrom = ""
            !txtFYEndDateTo = ""
            !txtFYmFrom = ""
            !txtFYmTo = ""
            !txtFYFrom = ""
            !txtFYTo = ""

        !txtBeginYearFrom.Enabled = llTrueOrFalse
        !txtBeginYearFrom.Locked = llTrueOrFalse <- when llTrueOrFalse is True the error occurs here
        !txtBeginYearTo.Enabled = llTrueOrFalse
        '!txtBeginYearTo.Locked = llTrueOrFalse <-Same here
        !txtFiscalYearFrom.Enabled = llTrueOrFalse
        '!txtFiscalYearFrom.Locked = llTrueOrFalse <-Same here
        !txtFiscalYearTo.Enabled = llTrueOrFalse
        '!txtFiscalYearTo.Locked = llTrueOrFalse <-Same here
        !txtFYEndDateFrom.Enabled = llTrueOrFalse
        '!txtFYEndDateFrom.Locked = llTrueOrFalse <-Same here
        !txtFYEndDateTo.Enabled = llTrueOrFalse
        '!txtFYEndDateTo.Locked = llTrueOrFalse <- ...
        !txtFYmFrom.Enabled = llTrueOrFalse
        '!txtFYmFrom.Locked = llTrueOrFalse
        !txtFYmTo.Enabled = llTrueOrFalse
        '!txtFYmTo.Locked = llTrueOrFalse
        !txtFYFrom.Enabled = llTrueOrFalse
        '!txtFYFrom.Locked = llTrueOrFalse
        !txtFYTo.Enabled = llTrueOrFalse
        '!txtFYTo.Locked = llTrueOrFalse

end with

 

But regardless of from where the code is run it always fails the same. I believe the problem exists due to the form being unbound hence the Dirty is negated.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

If I can remember correctly, you cannot disable or lock  a control when it has the focus. Is this the case?

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Good try but I was passed that one in the beginning. The correct answer is; An unbound form (a form with no recordset) for some reason can not handle the (dot) .Dirty and hence can not be marked as saved, or something like that. Anyway my work around was to use a dummy table (one with only 1 record) as the source for the form.

Then I added

...

Me.Recordset.MoveLast

Me.Recordset.MoveFirst

 

before the other lines of code above and presto it all worked.

 

Hope that helps someone out there in AccessLand.

Bill In Ottawa

 

 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I know this is an old thread, but I was looking for the same thing and your answer gave me an idea.

 

I am also using an unbound form and trying to lock a textbox after giving it a value (and unlocking it if there's no value to give it).  I just used:

 

Me.Dirty = False

 

before locking the textbox.  Works like a charm!  Thanks for showing my the way.

 

 

 

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated August 16, 2023 Views 1,992 Applies to: