Lock text box on current record

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hi there,
I have a subform with 2 fields and when I enter data in 1 field, I want the
other field to be locked so I can't enter data in it. Vice versa as well.
However, when I get to a new record I want to be able to still do the same
and not have any of the fields from that record locked.
However, if I navigate back to the 1st record where there is data in the 1st
field, I still want the 2nd field to be locked.
Any help is appreicated.
Thanks!
 
A

Al Campagna

gmazza,
Use the AfterUpdate of each control to lock the other.
And... use the OnCurrent event of each record to determine
which control is not null, and lock the other.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
B

Beetle

You could do this at the table level with a validation rule.
This would be a validation rule of the *table*, not of any
particular field. Open the table in design view, go to
View/Properties, and for the Validation Rule put;

([Field1] Is Null) XOR ([Field2] Is Null)

Or you could do it at the form level with VBA code;

Private Sub Form_Current()

If Me.NewRecord Then
Me!TextBox1.Locked = False
Me!TextBox2.Locked = False
Else
Me!TextBox1.Locked = (Not IsNull(Me!TextBox2))
Me!TextBox2.Locked = (Not IsNull(Me!TextBox1))
End If

End Sub

You'll probably want to have some method of unlocking the
text boxes for existing records as well (command button, etc.).
 

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