basic control reference syntax

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I'm getting runtime error 2185 that I can't ref a control that doesn't have
the focus when I do the following:

Private Sub FirstName_Change()
SetEmail
End Sub

Private Sub SetEmail()
If (isTextBoxEmpty([EmailAddress])) And _
(Not isTextBoxEmpty([FirstName])) And _
(Not isTextBoxEmpty([LastName])) _
Then
Dim s As String
s = LCase$(Left$([FirstName].Text, 1)) & _
LCase$([LastName].Text) & _
"@wynnlasvegas.com"
Me.EmailAddress = s
End If
End Sub

Private Function isTextBoxEmpty(ByVal aBox As TextBox) As Boolean
If IsNull([aBox]) Or [aBox].Text = "" Then
isTextBoxEmpty = True
Exit Function
End If
isTextBoxEmpty = False
End Function

Any help much appreciated,
Eric
 
Drop the ".Text" bit.

Unlike pure VB, the default property in Access is .Value.

The Text property applies to the text being entered into the control before
it becomes the Value, so Access is correctly saying that this property is
not available unless the control has the focus.
 
THANK YOU!! The book I've been "learning" from advised that [control].text
was in fact 'good programming practice"

Damn. You have a good book to recommend??

Eric

Allen Browne said:
Drop the ".Text" bit.

Unlike pure VB, the default property in Access is .Value.

The Text property applies to the text being entered into the control
before it becomes the Value, so Access is correctly saying that this
property is not available unless the control has the focus.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Eric said:
I'm getting runtime error 2185 that I can't ref a control that doesn't
have the focus when I do the following:

Private Sub FirstName_Change()
SetEmail
End Sub

Private Sub SetEmail()
If (isTextBoxEmpty([EmailAddress])) And _
(Not isTextBoxEmpty([FirstName])) And _
(Not isTextBoxEmpty([LastName])) _
Then
Dim s As String
s = LCase$(Left$([FirstName].Text, 1)) & _
LCase$([LastName].Text) & _
"@wynnlasvegas.com"
Me.EmailAddress = s
End If
End Sub

Private Function isTextBoxEmpty(ByVal aBox As TextBox) As Boolean
If IsNull([aBox]) Or [aBox].Text = "" Then
isTextBoxEmpty = True
Exit Function
End If
isTextBoxEmpty = False
End Function

Any help much appreciated,
Eric
 
Back
Top