Full Version: Pulling String From Substring
UtterAccess Forums > Microsoft® Access > Access Forms
I am trying to automate a user creation form to reduce the amount of data the admin needs to enter when creating a user. I am having them enter first the username which is comprised of the users firstname a dot (.) and the last name so in my case my username would be "robby.aube".
What I am trying to do with this is have the First and Last name fields populate from that username. I have the following string extraction code which I thought would work but it only works for the FName and not the LName...
username = Me.txtUserName
Me.txtFName = Left(username, InStr(1, username, ".") - 1)
Me.txtLName = Right(username, InStrRev(username, ".", -1))

Any ideas as to what I am doing wrong? I need to extract all caracters before the . for the first name and all caracters after the . for the last name not including the . itself...
Try this instead:
sername = Me.txtUserName
Me.txtFName = Left(username, InStr(1, username, ".") - 1)
Me.txtLName = Mid(1, username, InStr(1, username, ".") + 1))
InStr and InStrRev return a value that indicates the position of the particular character. Using it as you were is causing it to fetch the number of characters from the right end of username that corresponds to the position of the "." So if the "." is in say position 5, then Right would return the 5 rightmost positions of username when what you really want is all characters to the right of the ".".
try this:
Private Sub TxtUsername_AfterUpdate()
End Sub

hope this helps
Jeff B.
Let's see, FName, 'dot', LName versus FName, LName ... how does that make for less data entry?
ather than have the user enter the full name into a single control, why not have two controls (and two underlying fields): FName and LName?
Also, how will your code "parse" the following (possible and even probably) entries?
Joseph."Billy Bob".Johnson
Good luck!
ok that worked... thanks!!
Jeff B.
The [censored] filter needs a little tweak ... Jean Claude's last name is not spelled the same way as the [censored] curse word.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.