By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,209 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,209 IT Pros & Developers. It's quick & easy.

Automate username when making account

rcollins
100+
P: 234
What I need to do is to have the login name box create the user name from the name inputted. I would like to have it create f initial l name except when that is already used, then I would like f initial m initial l name. How is this done?
Nov 18 '08 #1
Share this Question
Share on Google+
8 Replies


ADezii
Expert 5K+
P: 8,638
I am a little confused on tour request, RCollins. Are you requesting to dynamically create a User Name based on a Name that is entered into a Login Form of some kind? This is provided, of course, if the User does not already exist. If this is so, what is the logic behind this approach?
Nov 18 '08 #2

rcollins
100+
P: 234
I have an old dos program we use now, I am trying to replace this with an access database. The form is simple.
Employee Code
LastName
FirstName
MI
Job Title
UserID
UserPassword
When the lady inputs new info, after she gets the LastName FirstName MI entered I want the UserID to be populated with FI LastName automatically, Unless that is already used. Then I want it to put FI MI LastName so there is a difference.
Nov 18 '08 #3

ADezii
Expert 5K+
P: 8,638
I have an old dos program we use now, I am trying to replace this with an access database. The form is simple.
Employee Code
LastName
FirstName
MI
Job Title
UserID
UserPassword
When the lady inputs new info, after she gets the LastName FirstName MI entered I want the UserID to be populated with FI LastName automatically, Unless that is already used. Then I want it to put FI MI LastName so there is a difference.
  1. I'll assume your Data is stored in a Table named tblDOS, simply replace with your own Table Name in Line #18.
  2. I'll also assume that you require all 3 values, namely, the First, Last Name, and MI.
  3. Copy and Paste the following Sub-Routine into the General Declaratiosn of your 'Form's' Class Module:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub PopulateUserID()
    2. Dim strFI As String             'First Initial
    3. Dim strMI As String             'Middle Initial
    4. Dim strLN As String             'Last Name
    5.  
    6. 'I'll assume you require all 3 entries
    7. If IsNull(Me![LastName]) Or IsNull(Me![FirstName]) Or IsNull(Me![MI]) Then Exit Sub
    8.  
    9. 'If you get here, a Last, First Name, and MI have been entered
    10. strFI = Left$(Me![FirstName], 1)
    11. strMI = Me![MI]         'Should check for a '.'
    12. strLN = Me![LastName]
    13.  
    14. 'Debyug code
    15. 'Debug.Print strFI & " ==> " & strMI & " ==> " & strLN
    16.  
    17. 'Does First Initial/Last Name already exist in UserID?
    18. If DCount("*", "tblDOS", "Left([UserID], 1) = '" & _
    19.    strFI & "' And Mid([UserID], 2) = '" & strLN & "'") > 0 Then     'Yep
    20.   Me![UserID] = strFI & strMI & strLN
    21. Else        'Combination does not exist, ergo
    22.   Me![UserID] = strFI & strLN
    23. End If
    24. End Sub
  4. In the AfterUpdate() Event of the [FirstName], [LastName], and [MI] Fields, Copy and Paste this single line of code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub FirstName_BeforeUpdate(Cancel As Integer)
    2.   Call PopulateUserID
    3. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub LastName_AfterUpdate()
    2.   Call PopulateUserID
    3. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub MI_BeforeUpdate(Cancel As Integer)
    2.   Call PopulateUserID
    3. End Sub
  5. If you have trouble understanding the logic, let me know and I'll explain.
  6. Be advised that this code in not foolproof, since it does not check for the possibility of duplicate FI/MI/LastName entries in UserID. To avoid this possibility, simply Index this Field with No Duplicates allowed, or expand the code.
Nov 18 '08 #4

rcollins
100+
P: 234
I get an error. I changed everything to meet what I had, heres the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub PopulateUserID()
  2. Dim strFI As String             'First Initial
  3. Dim strMI As String             'Middle Initial
  4. Dim strLN As String             'Last Name
  5.  
  6. 'I'll assume you require all 3 entries
  7. If IsNull(Me![LNAME]) Or IsNull(Me![FNAME]) Or IsNull(Me![MI]) Then Exit Sub
  8.  
  9. 'If you get here, a Last, First Name, and MI have been entered
  10. strFI = Left$(Me![FNAME], 1)
  11. strMI = Me![MI]         'Should check for a '.'
  12. strLN = Me![LNAME]
  13.  
  14. 'Debyug code
  15. 'Debug.Print strFI & " ==> " & strMI & " ==> " & strLN
  16.  
  17. 'Does First Initial/Last Name already exist in UserID?
  18. If DCount("*", "EMPLOYEE", "Left([USERID], 1) = '" & _
  19.    strFI & "' And Mid([USERID], 2) = '" & strLN & "'") > 0 Then     'Yep
  20.   Me![USERID] = strFI & strMI & strLN
  21. Else        'Combination does not exist, ergo
  22.   Me![USERID] = strFI & strLN
  23. End If
  24. End Sub
  25.  
I pasted the line into each last firs and mi

Here is the error that I get
"Employee Database can't find the macro "Call PopulateUserID. the macro doesn't exist, or the macro hasn't been saved."
Whats this?
Nov 20 '08 #5

rcollins
100+
P: 234
got it to work thank you
Nov 20 '08 #6

ADezii
Expert 5K+
P: 8,638
got it to work thank you
You are quite welcome.
Nov 20 '08 #7

rcollins
100+
P: 234
Hey, can I ask how would I make this return in lowercase?
Nov 20 '08 #8

rcollins
100+
P: 234
nevermind, LCase( all the other stuf)
Nov 20 '08 #9

Post your reply

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