Selasa, 19 Juli 2011

RE: [AccessDevelopers] need a string function

 

Looks like from a subsequent email you got it figured out, but the problem with the code in your original post was that your first line of code was
 
If Me.txtLastName = Left("xxx",3) Then
 
which is equivalent to just saying   If LastName = "xxx"
 
For this to be true the user would have had to enter exactly "xxx".  Nothing less.  Nothing more.  I think what you wanted was to check to see if the left 3 characters of LastName was = "xxx", which means the Left function should have been used on the LastName variable, like this:
 
If Left(Me.txtLastName, 3) = "xxx" Then
 
You seem to have figured this out with your later email where you used
 
If Mid(Me.txtLastName, 1, 3) = "xxx" Then
 
 
As far as which Event to use, you would typically use the AfterUpdate event for the textbox, which catches every time the text is edited at all.  The LostFocus event will probably work too, but it would trigger every time that textbox received the focus and then lost it (for instance, by just tabbing through the controls) even if nothing was edited.  Wouldn't really hurt anything except the code would trigger a few extra times when it's not really necessary.
 
Hope that helps,
Toby
 
-----Original Message-----
From: AccessDevelopers@yahoogroups.com [mailto:AccessDevelopers@yahoogroups.com] On Behalf Of dwightknotgunn
Sent: Monday, July 18, 2011 8:22 PM
To: AccessDevelopers@yahoogroups.com
Subject: [AccessDevelopers] need a string function

 

If Me.txtLastName = Left("xxx", 3) Then MsgBox "Not a good name", vbOKOnly + vbCritical, "Important Program"
Me.txtLastName = Null
Me.txtFirstName = Null
End If
If the user puts in 4x's then the Msgbox is bypassed by Access. I want the MsgBox to show up everytime.

__._,_.___
Recent Activity:

Please zip all files prior to uploading to Files section.
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar