vba lock a bound date box on form

shutzy

Registered User.
Local time
Today, 20:25
Joined
Sep 14, 2011
Messages
775
i want to use vba to lock or diable a date box on my form. i have used[button].Enabled = Falsethis works ok for buttons but doesnt seem to work for my date fieldMe.OrderDate.Enabled = Falsei get an errormethod or data member not found. it highlights the .Enabled partany advise?
 
You can't lock or disable a field, only a control, so you need to verify that you're referencing the name of the control (text box, etc.), which may be different than the name of the field (in the underlying table or query).
 
ive tried it both ways. i tried the actual name and the control source.

the control source name is OrderDate
the date box is DateOfTreatment.

any suggestions?
 
Just to clarify, you have a text box where the name of the field in the Control Source is OrderDate and the name of the text box itself is DateOfTreatment, and when you put the following line in a procedure;

Me!DateOfTreatment.Enabled = False

you get a "Method or Data Member not found" error?
 
yes.

the actual vba was
[DateOfTreatment].Enabled = False

i even copied and pasted the name just to make sure there was no spelling error
 
i have used this for the time box i have

DoCmd.SetProperty "comboOrderTime", acPropertyEnabled, "0"

this works but it doesnt work for the date box
 
sorry ive just tried it again and it works now. i must not of tried
DoCmd.SetProperty "DateOfTreatment", acPropertyEnabled, "0"
before

thanks for your help
 
The DoCmd is over the top. Just reference the control using "Me."

Me.DateOfTreatment.Enabled = False

I actually prefer to use:

Me.DateOfTreatment.Locked = True

Because that prevents changes but still allows the contents to be selected should the user want to copy it and paste it elsewhere.
 

Users who are viewing this thread

Back
Top Bottom