Hello,
I am trying to intercept the space bar key entry in a textbox to insert
special characters.
Private Sub ClientEmail_KeyPress(KeyAscii As Integer)
Dim strEmail As String
'Simplify e-mail address entry using spacebar
If KeyAscii = 32 Then
strEmail = Me.ClientEmail
If InStr(strEmail, "@") = 0 Then
Me.ClientEmail.Value = strEmail & "@"
Else
Me.ClientEmail.Value = strEmail & "."
End If
End If
End Sub
I'm experiencing 2 problems.
1- an error occurs at line 'strEmail = Me.ClientEmail' stating that it is
null even after entering a string value. I can get around this issue by
placing a me.dirty=false before the line, but I still don't understand the
underlying problem as there is a string value in the textbox when the error
is triggered?
2- My real issue, is that after this code runs, the textbox gets blanked?!?!
If I do an undo the proper text appear. Why oh Why is my code blanking the
entry altogether?
Daniel P
Daniel - 05 Jun 2007 17:19 GMT
With a little fiddling I figured out that I need to use Me.ClientEmail.Text
rather than Me.ClientEmail.
However, i now get the extra characters to show but I also get the space
(Chr(32)). How can I eliminate it from the entry. I want the spcae to
trigger the action but not show in the entry.
Thank you,
Daniel P
> Hello,
>
[quoted text clipped - 27 lines]
>
> Daniel P
Daniel - 05 Jun 2007 17:30 GMT
Problem solved. the saying is true: "you learn something new every day!"
The solution is below should anyone ever be trying to solve this same issue.
Private Sub ClientEmail_KeyPress(KeyAscii As Integer)
Dim strEmail As String
'Simplify e-mail address entry using spacebar
If KeyAscii = 32 Then
strEmail = Me.ClientEmail.Text
If InStr(strEmail, "@") = 0 Then
Me.ClientEmail.Text = strEmail & "@"
Else
Me.ClientEmail.Text = strEmail & "."
End If
DoCmd.CancelEvent 'Stops the space from being placed in the string
End If
End Sub

Signature
Hope this helps,
Daniel P
> With a little fiddling I figured out that I need to use Me.ClientEmail.Text
> rather than Me.ClientEmail.
[quoted text clipped - 38 lines]
> >
> > Daniel P
Dirk Goldgar - 05 Jun 2007 18:51 GMT
> DoCmd.CancelEvent 'Stops the space from being placed in the
> string
An interesting solution. The more common solution is to set the event
procedure's KeyAscii argument to zero:
KeyAscii = 0

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)