Enable/Disable Control

A

alison.justice

I have a form that has a control named CategoryID, what I am trying to
accomplish is if the control has data in it then the data cannot be changed,
but if there is no data in the control then it is available so I could enter
information then once the data is entered it basically disable the control
how would I do this.

And on the property portion of the form is there an OnCurrent in Access 2007
I don't see it?
 
A

Arvin Meyer [MVP]

Yes there is a Current event. Use something like:

If Len(Me.txtControlName & vbNullString) >= 1 Then
Me.txtControlName.Locked = True
Else
Me.txtControlName.Locked = False
End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Disclaimer: Any code or opinions are offered here as is. Some of that
code has been well tested for number of years. Some of it is untested
"aircode" typed directly into the post.
 
D

Dirk Goldgar

alison.justice said:
I have a form that has a control named CategoryID, what I am trying to
accomplish is if the control has data in it then the data cannot be
changed,
but if there is no data in the control then it is available so I could
enter
information then once the data is entered it basically disable the control
how would I do this.

And on the property portion of the form is there an OnCurrent in Access
2007
I don't see it?


There certainly is. Are you looking at the Events tab of the property
sheet? Access 2007 did reorder some of the properties, IIRC, but it didn't
take away the Current event or the On Current property.

You're right to be thinking of the Current event. I'd use code like this
for the Current event:

'------ start of example code ------
Private Sub Form_Current()

Me.CategoryID.Enabled = IsNull(Me.CategoryID)

End Sub
'------ end of example code ------
 
A

alison.justice

Yes I was looking at the Event tab and did not see it listed, I'm using
Access 2007.

Thank you for the code, I tried to figure it out myself, but sometimes those
books don't help.
 

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