473,388 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Creating a username field

Hi. I have a table with firstName & lastName. I need to run an sql to create a userName. I want the username to be the first initial of firstName and first seven letters of lastName.

I have this so far:
Expand|Select|Wrap|Line Numbers
  1. username: LCase(Left([firstName],1) & "" & (Left([lastname],7)))
but am running into a small problem.

Some of the last names are shorter than 7 characters which is ok, but these "shorter names" have trailing spaces and characters such as " / " and other words following. I need to be able to trim anything to the right of these characters and am stuck here.
Apr 6 '11 #1
5 1748
Mariostg
332 100+
functions like Trim() and Replace() may help.
But to be clear, you might want to show us real exemples of what you get vice what you want.
Apr 6 '11 #2
firstName: jack
lastName: jones / group1
username: jjones /

desired username: jjones

I'm trying to have my qry return "jjones".
In the instance where the lastName is less than eight characters, it is including the first blank space and the backslash.
Apr 6 '11 #3
Mariostg
332 100+
Expand|Select|Wrap|Line Numbers
  1. Function MakeUserName(firstName As String, lastname As String) As String
  2.     Dim username As String
  3.     lastname = Trim(Split(lastname, "/")(0))
  4.     username = LCase(Left([firstName], 1) & (Left([lastname], 7)))
  5.     MakeUserName = username
  6. End Function
  7.  
Output:
Expand|Select|Wrap|Line Numbers
  1. ?MakeUserName("john", " jones / group1")
  2. jjones
  3.  
Apr 6 '11 #4
Thank you Mariostg!
Is there a way to use this in my qry or must I use a form?

Thank youa again
Apr 6 '11 #5
Mariostg
332 100+
It would be best to place this function inside a module.
Then you can call the function from your your query:
Expand|Select|Wrap|Line Numbers
  1. username: MakeUserName([lastname],[firstname])
  2.  
It gives you much more control and makes things cleaner.
Apr 6 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lando Chez | last post by:
Hi I want to create fileds on my form that can not be manually edited through the UI of the form. Instead the (visible) content is changed through changes on other parts of the form. e.g....
1
by: MLH | last post by:
I just created user name & pass in Access 97 - a new installation that has never before had the system mdw modified. I exited Access and now am unable to login as Admin (which I never assigned a...
5
by: keith | last post by:
This may seem simple, but I'm having a bit of trouble figuring out exactly how to do it. I'm accessing a database through an ODBC link, and I have a query that returns only jobs completed that day...
3
by: Dixie | last post by:
I am trying to write code to add a field called "Additional" to an existing table called "Faculty". When I run it as an on click event, it stops at the line, .append fldTemp with the error message...
4
by: Mark | last post by:
How can i get the maximum allowed length for a field in a SQL database? ie the value defined when creating a text field in a table, in a SQL database. As i want to set the max length of a text...
4
by: John | last post by:
Hi Is it possible to add a field to an sql server 20005 table programmatically by a vb.net app while the vb.net app has the table being viewed on a vb.net form? Thanks Regards
1
by: alfrc | last post by:
Can you help me on how to create queries with dynamic field. Meaning field to be displayed may be either coming from text box value...... combo box value... etc. Example: I have a table with the...
1
by: Anatoly Kurilin | last post by:
Hi, I did not find in Help the way for creating AutoNumber field in code. I've tried to adapt these lines for that purpose Set fldClientID = .CreateField("ClientID", dbLong) .Fields.Append...
2
by: Emax | last post by:
Problem: I have created database in MS SQL and Data Form in MS Access 2003. The table DepEmployee has three column. EmpID (Pk), Dep, Rc I want to auto generate EmpID with Dep, Rc when I click add...
2
by: phpmagesh | last post by:
Hai dudes, i am working in Xt-Commerce (Online shopping site), in that they have few general things as common for every product, now i want to include another detail about my product. Ex: i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.