Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking text boxes that are NOT NULL

Status
Not open for further replies.

djmousie

Technical User
Oct 10, 2001
164
US
I have a form that is linked to table information. When I click on new record it submits a blank record on the form. I want to be able to type into a box that is NOT null, however, once a form has text in it, I want it locked so noone can go in and change it accidently.

Any help?

Thanks
 
What if you NEED to change the contents?

One answer to your question would be to code an On Enter event.

If IsNull([controlname]) then
me.[controlname].locked = false
else
me.[controlname].locked = true
end if



HTH,
Bob [morning]
 
How would I write that as an expression if you dont mind me asking?
 
Hi!

Bring up your form in design view.

Right-click a control (field) that you want to lock after data has been entered.

Select Properties.

Select the Event tab.

Select the On Enter line.

Select the square on the right containing three dots ...

Select Code Builder.

Copy/Paste the code from above between the two lines.

Change [controlname] to the name of the form field.
(You can verify exactly what this is by selecting the
Other tab on properties - It's listed on the Name line.)

Select Debut, then compile to make sure all references are correct.

Close (X) the VBA window.

Close the database.
(Not required, but seems to resolve some Access
idiosyncrasies that occasionally crop up.)

Open the database, form and test.

Repeat entering code for each form control that you want to work this way.




HTH,
Bob [morning]
 
Footnote

You said:

"When I click on new record it submits a blank record on the form. I want to be able to type into a box that is NOT null, however, once a form has text in it, I want it locked so noone can go in and change it accidently."

The code I proposed assumes that no entry yet DOES reflect null. If the field contains something else, like space(s) or zero-length string, it can still be handled, but must be know.

Alternatively, at the form level instead of the individual control, you could check the NewRecord property. If true, then set AllowEdits to true, else false. That would be at the form level and disallow changes to ALL controls on the form.



HTH,
Bob [morning]
 
By the way, what does the function "Me." do? I know very little VBA
 
Ahh forget it, it does the same thing as [Forms]! in a query.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top