[AccessD] Locking a textbox based on other form controls

Charlotte Foust cfoust at infostatsystems.com
Thu Aug 17 11:09:38 CDT 2006


The Change event happens on every keystroke, including the first one.
Type "a" and that's a change and you're trying to lock the control you
just typed an "a" into without leaving the control and committing the
value.  That's what the message means.  I think you want the afterupdate
event of the control, not the change event.

Charlotte Foust 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Christopher
Jeris
Sent: Thursday, August 17, 2006 8:40 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Locking a textbox based on other form controls

-----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-----
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list