SetFocus

EndersG

Registered User.
Local time
Today, 09:12
Joined
Feb 18, 2000
Messages
84
I was struggling with a function using the Form Current event.

I tried to enable and disable a field (field1) based on the value of a textbox (textbox1). If textbox1 equals Y then field1 was enabled and if textbox1 was equal to N then Field1 was disabled for every new record you select. So I went into the Form_Current() module and proceeded to write (using the Build... feature, mind you) the following code:

Private Sub Form_Current()
If Me![textbox1].text = "Y" Then
Me![subForm].[Form]![field1].enable = true
Else
Me![subForm].[Form]![field1].enable = false
End If
End sub

Needless to say, with this approach, I got debugging errors telling me I had to use SetFocus on the control and whatnot. I tried everything. It wasn't until after I was desperate that I deleted the leading Me! identifier and trailing .Text property that I finally got it to work.

Private Sub Form_Current()
If textbox1 = "Y" then
[subForm].[Form]![field1].enable = true
Else
[subForm].[Form]![field1].enable = false
End If
End sub

And I didn't have to use SetFocus. Why wouldn't it work with the more descriptive identifiers? Please advise what I did wrong.
 
Everything is obvious when you see it. A textbox does not have a 'text' property it has a value property, the value property is the default property so by removing the '.text' you are correctly picking up the 'value' from the text box. Voila! it works.

Note: you could also leave out the '.FORM' as this is the default property for a sub form control. I tend to leave it in, as well as the 'me' to make my code easier to read.
Regards
trevor from www.accesswatch.co.uk
 

Users who are viewing this thread

Back
Top Bottom