Disable Textbox

J

Jdawg

I believe my question is simple, but I seem to be struggling to
determine what I need to do. I have a form that I am working on and I
have a text box with a Control Source of SpouseName. In addition, I
also have a textbox with a Control Source of MobilePhone. If this
'SpouseName' text box has no value, I would like for the user to not
only be able to enter any information in the 'MobilePhone' textbox,
but I would also like the user to be unable to view the textbox. I am
not sure if I need to be using AfterUpdate or if I should be using
BeforeUpdate.

Any help would be greatly appreciated.
 
J

Jeanette Cunningham

Hi,
On the form's properties sheet, set the textbox for MobilePhone visible
property to No.
This will hide the textbox until a user types in the SpouseName textbox.
In the after update event for the SpouseName textbox, put code like this:

If Not IsNull(me.txtSpouseName) then
Me.txtMobilePhone.Visible = True
Else
Me.txtMobilePhone.Visible = False
End If

the above will be OK for data entry form.

When you have a form editing data, you need similar code in the Current
event.
Private Sub Form_Current()
If Not IsNull(me.txtSpouseName) then
Me.txtMobilePhone.Visible = True
Else
Me.txtMobilePhone.Visible = False
End If
End Sub

Jeanette Cunningham
 
B

Beetle

If I understand your question correctly, you want the mobile phone textbox
disabled if there is no info in the SpouseName textbox.

You probably will want to put this code in both the forms OnCurrent event
and the SpouseName controls AfterUpdate event. The code might look something
like;

Private Sub Form_Current

If IsNull (Me.txtSpouseName) Or Me.txtSpouseName = "" Then

Me.txtSpouseMobilePhone.Enabled = False

End If

Using the enabled property will make the textbox "gray" out. If you want to
make it completely invisible then use

Me.txtSpouseMobilePhone.Visible = False

HTH
 

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