Combining fields in a text box

niak32

Registered User.
Local time
Tomorrow, 09:39
Joined
Nov 1, 2008
Messages
28
I am making a staff form, it has firstname, lastname and a quickname field

What I am trying to do is to make a suggestion for a quickname \ callsign by taking the first character of the first name, a "." then the last name.

Trying to use Left and Len with out much success. I had it working at one stage but Len does not count a " " as a character and that just threw it all off.

Code:
Dim strFNametxt As String
strFNametxt = Me.txtFirstName

Dim intFName As Integer
intFName = Len(strFNametxt) - 3

Dim strStuff As String
strStuff = Left(strFNametxt, InStr(1, strFNametxt, " ", vbTextCompare) - intFName)

Me.txtQuickName = strStuff

now it only works with one or 2 characters, does not return anything with 3 chars and errors on 4 or above "Invalid procedure or call argument"

Don't mean to spam the forums, I generally get one day in a blue moon to work on a database so I'm trying to make the most of it.
 
Not sure what's going on with your Left function, but your code doesn't correspond to what you say you want to do:
taking the first character of the first name, a "." then the last name.
So, unless I've misunderstood, I would think all you need is:
Code:
Me.txtQuickName = Left(Me.txtFirstName,1) & "." & Me.txtLastName
(Assuming you have a text box for Last Name...)

And don't be shy about posting your questions - that's what the forum is for! :)

HTH,
John
 
Worked like a charm, the site I got my info from was for the first word. took me a while to figure it out.

Cheers!
 
Just a tip...

When writing code it is good practice to put all your DIM statements together at the top of your code. This will avoid dimensioning a variable twice or putting it in a loop or some other misdemeanour.

Chris
 

Users who are viewing this thread

Back
Top Bottom