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?
Automate username when making account
Collapse
X
-
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? -
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
-
Originally posted by rcollinsI 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.- I'll assume your Data is stored in a Table named tblDOS, simply replace with your own Table Name in Line #18.
- I'll also assume that you require all 3 values, namely, the First, Last Name, and MI.
- 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 - 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
- If you have trouble understanding the logic, let me know and I'll explain.
- 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
-
I get an error. I changed everything to meet what I had, heres the code
I pasted the line into each last firs and miCode: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
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
Comment