Automate username when making account

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rcollins
    New Member
    • Aug 2006
    • 234

    Automate username when making account

    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?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    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?

    Comment

    • rcollins
      New Member
      • Aug 2006
      • 234

      #3
      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.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by rcollins
        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:
          Code:
          Private Sub PopulateUserID()
          Dim strFI As String             'First Initial
          Dim strMI As String             'Middle Initial
          Dim strLN As String             'Last Name
          
          'I'll assume you require all 3 entries
          If IsNull(Me![LastName]) Or IsNull(Me![FirstName]) Or IsNull(Me![MI]) Then Exit Sub
          
          'If you get here, a Last, First Name, and MI have been entered
          strFI = Left$(Me![FirstName], 1)
          strMI = Me![MI]         'Should check for a '.'
          strLN = Me![LastName]
          
          'Debyug code
          'Debug.Print strFI & " ==> " & strMI & " ==> " & strLN
          
          'Does First Initial/Last Name already exist in UserID?
          If DCount("*", "tblDOS", "Left([UserID], 1) = '" & _
             strFI & "' And Mid([UserID], 2) = '" & strLN & "'") > 0 Then     'Yep
            Me![UserID] = strFI & strMI & strLN
          Else        'Combination does not exist, ergo
            Me![UserID] = strFI & strLN
          End If
          End Sub
        4. In the AfterUpdate() Event of the [FirstName], [LastName], and [MI] Fields, Copy and Paste this single line of code:
          Code:
          Private Sub FirstName_BeforeUpdate(Cancel As Integer)
            Call PopulateUserID
          End Sub
          Code:
          Private Sub LastName_AfterUpdate()
            Call PopulateUserID
          End Sub
          Code:
          Private Sub MI_BeforeUpdate(Cancel As Integer)
            Call PopulateUserID
          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.

        Comment

        • rcollins
          New Member
          • Aug 2006
          • 234

          #5
          I get an error. I changed everything to meet what I had, heres the code
          Code:
          Private Sub PopulateUserID()
          Dim strFI As String             'First Initial
          Dim strMI As String             'Middle Initial
          Dim strLN As String             'Last Name
            
          'I'll assume you require all 3 entries
          If IsNull(Me![LNAME]) Or IsNull(Me![FNAME]) Or IsNull(Me![MI]) Then Exit Sub
            
          'If you get here, a Last, First Name, and MI have been entered
          strFI = Left$(Me![FNAME], 1)
          strMI = Me![MI]         'Should check for a '.'
          strLN = Me![LNAME]
            
          'Debyug code
          'Debug.Print strFI & " ==> " & strMI & " ==> " & strLN
            
          'Does First Initial/Last Name already exist in UserID?
          If DCount("*", "EMPLOYEE", "Left([USERID], 1) = '" & _
             strFI & "' And Mid([USERID], 2) = '" & strLN & "'") > 0 Then     'Yep
            Me![USERID] = strFI & strMI & strLN
          Else        'Combination does not exist, ergo
            Me![USERID] = strFI & strLN
          End If
          End Sub
          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?

          Comment

          • rcollins
            New Member
            • Aug 2006
            • 234

            #6
            got it to work thank you

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by rcollins
              got it to work thank you
              You are quite welcome.

              Comment

              • rcollins
                New Member
                • Aug 2006
                • 234

                #8
                Hey, can I ask how would I make this return in lowercase?

                Comment

                • rcollins
                  New Member
                  • Aug 2006
                  • 234

                  #9
                  nevermind, LCase( all the other stuf)

                  Comment

                  Working...