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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access Help

Status
Not open for further replies.

coolskater49

Technical User
Joined
Nov 20, 2002
Messages
20
Location
GB
i have a text box that i want to automatically disable if it does not contain a value and to be enabled when it does contain a value.

hope someone can help.
thanks.
 
Hi

In the oncurrent event of the form

txtBox.Enabled = Not IsNull(txtBox)

Note you cannot set the enabled property to false if the control has the focus, so you may need to move focus elsewhere eg MyOtherControl.SetFocus

I am assuming by 'empty you mean null.

You need to substitute your own control names
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Well i've just tried that and it doesnt seem to work.

Within my form i have a combo box which when a record is selected, it displays the corresponding fields in text boxes. One of these text boxes does not always contain a value depending on which record the user selects. If, for the chosen record the text box is null(empty) i want it to be disabled, and when a record is selected that contains a value in this text box i want it to be enabled.

hope this better description helps.
thanks.
 
Hi

Does your reply imply that the form is not a bound form?

If it is not a bounf form, presumably you have code in the after update event of the combo box to open the recordset for the appropriate record, and populate the controls on the form?, if yes, put the txtBox.Enabled = Not IsNull(txtBox) after the txtBox = Rs!MyValue



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
well this is the code im using on the combo box. i tried the the code you gave and it didnt work.

Private Sub Combo11_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[employee_id] = '" & Me![Combo11] & "'"
Me.Bookmark = rs.Bookmark
vehicle_registration.Enabled = Not IsNull
(vehicle_registration)
End Sub

the text box is vehicle_registration

thanks a lot.
 
Hi

OK, so you are using a bound form.

Could you be a bit more explicit about 'does not work'

What happens?

Any error messages

Could you past the code which you have in the oncurrent event of the form

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
ok,
the code shown above does not disable the vehicle_registration text box. when the text box is null(empty) it is still enabled. no error messages are shown and i have no code in the oncurrent event on the form.
thanks

paul.
 
Try using the function NZ(<variable>,<result>)

Example:
(Nabbed from earlier post)
Private Sub Combo11_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst &quot;[employee_id] = '&quot; & Me![Combo11] & &quot;'&quot;
Me.Bookmark = rs.Bookmark
vehicle_registration.Enabled = (nz(len(vehicle_registration),0)>0)
End Sub

This checks the length of vehicle_registration.
If it has a length this is compared to 0 - greater than = enabled.
If it doesn't have a length or is null the null is converted to 0 and then the greater than check is performed and ends up false...

You can probably use it on the &quot;OnCurrent&quot; event.


Vince
 
Hi

As Ecniv says, it should be in the OnCurrentEvent as per my earlier post

Also in my fisrt post I did say I was assuming that by empty you meant null, if this is not so use of Nz() and Len() will allow for treating a Registration number of spaces as if it was empty.

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
thanks for your post.
i have tried this code yet the vehicle_registration text box is still always enabled. when it is null(empty) it still remains enabled.
hope someone can help.

paul.
 
does anyone have any new ideas or ideas as to what i might be doing wrong because the text box stays enabled all of the time, no matter what the content is.

thanks a lot
paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top