Error msg - 'You can't lock a control while it has unsaved changes

G

Guest

I have a textbox that sometimes displays a calculated value (in which case it
needs to be locked) and sometimes is used for data entry (needs to be
un-locked). If I lock it initially it works fine. Then I can un-lock it and
that works. But then if I go back and try to lock it again I get this
message. It is an unbound field. What can I do to prevent this error? When I
say locked/unlocked I just mean setting it's Locked property to True or
False. Any help is appreciated. Thanks.
 
G

Guest

Hi Jim

As the error message says, you can't lock a textbox until you have saved any
changes. In this context 'saving' a change will occur when you pass focus
away from the textbox.

I presume that you are locking the textbox through its on-click event. If
so, then a 'quick and dirty' way of forcing the save is to pass the focus to
another textbox, then back to the original.

So, if your textbox is, say textbox1, create another textbox, say textbox2.

The on-click event coding is then:

DoCmd.GoToControl "textbox2"
DoCmd.GoToControl "textbox1"
Me.textbox1.Locked = Not Me.textbox1.Locked

Cheers.

BW
 
G

Guest

That's what I would have thought, but if I try to set the focus to another
control it tells me I can't, with a similar message to when I try to lock the
one control. Then when I try to close the form it tells me I can't save the
record at this time. It's an unbound form, so that shouldn't happen, should
it? I looked at all my form properties, controls and code and can't find
anything out of the ordinary. I've done a LOT of VBA coding and and am
baffled, though I'm sure it's just a stupid coding mistake on my part that
I'm overlooking.
 
G

Guest

Also I forgot to mention that I am trying to lock the textbox in the
beforeUpdate event proc of a combobox on that form. So the textbox shouldn't
have focus anyway, since the combo box is the thing that was updated and last
had focus.
 
G

Guest

I'm having the same issue with a listbox.

On the click event of one listbox (ListA), I call a routine that determines
which controls on the form should be available for editing. If a control
should not be available and contains data, the control is cleared then
locked. Works on everything but a second listbox (ListB).

First, I select to return the list to the top most position and to unselect
the selected item if any. Then, I set unselect it and lock it.
ListB.Selected(1) = True
ListB.Selected(1) = False
ListB.locked = true

If I don't perform the select, I can lock and unlock the control at will. It
will not allow me to move the focus to ListB or any other control.

Good to know I'm not the only one having a problem with this error.
 

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