[AccessD] Locking a textbox based on other form controls

Christopher Jeris cjeris at fas.harvard.edu
Thu Aug 17 10:40:19 CDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charlotte Foust wrote:
> Only if you don't set the form's recordset or RecordSource property from
> code.  And Text is a read only property of Access textboxes.  It can
> only be read when the control has the focus.  Otherwise, you have to use
> the Value property.  What you're describing sounds a lot like what
> happens when a bound textbox has a change made in code to the underlying
> recordset and the user then tries to change the value from the UI and
> save the record.  The two changes collide and Access complains mightily.

Okay, here's a minimal example that illustrates the problem.

Create a blank form Form1 in Access XP.
Add two controls to it:  text-boxes Text0 and Text2.
The entire content of the VB module Form_Form1 is as follows.

  Option Compare Database
  Option Explicit

  ' The function of Text2 is that when it is changed, Text0 is locked:
  Private Sub Text2_Change()
      Me![Text0].Locked = True
  End Sub

Save this form and module.  Open the form in Form View.  Then click in
Text2 and try to change the populated value.

  Run-time error '2166':
  You can't lock a control while it has unsaved changes.

What unsaved changes?  No value has ever been typed or set into Text0 for
the entire lifetime of this database file!  What am I missing here?

thanks, Chris Jeris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFE5I3j5ICCNV0oGWARAiTLAJwIeLB25P4ShbNoj86qpEyYzoEBAACaAp4m
5l1fYQa2SPf+xL1njBiyn84=
=9UY7
-----END PGP SIGNATURE-----



More information about the AccessD mailing list