Append Part of a Text Field to another field

matthewnsarah07

Registered User.
Local time
Today, 07:30
Joined
Feb 19, 2008
Messages
192
Code:
UserName:IIF(InStr([EmailAdr],"@")> 1,Left([EmailAdr],Instr([EmailAdr],"@")-1),"")

This first checks if there is an @ in the phrase, and if so it parses everything to the left of the position where the @ sign appears in the email address, else it returns ""
 
Since your form is called "frmAddStaff", it follows you are going to ADD a record to your table. What other fields make up the table? Don't you want to add those as well?
Or, does the table exist and only the email is currently blank?

You will need some code in the After Update event of the email field on the form.
You would use Instr(Me.email,"@") to ensure that a "@" actually exists.
The Instr(Me.email,"@") will give you the position of the "@" in the field. This must not = 0(or the character wasn't found).

Then the string you want will be similar to this
Left(Me.email,Instr(me.email,"@")-1)
which says -- take the characters at the Left of Me.email for a length equal to the position of the "@" -1

Good luck.


Update: Looks like David answered while I was typing.
 
Thank you both for your assistance, that has worked perfectly.

I had picked this code up but wasn't sure how it worked
 

Users who are viewing this thread

Back
Top Bottom