I have code below to analyze existing network username to potential new user's usernames. If no match then user gets first initial and lastname if there is a match (conflict) then the user gets first two character from their firstname and lastname.
Following code works except right after the insert statement i want to rst.requery to get the newly created username in in the rst recordset but it won't work. I have attached the database Access 2000, when you click on the form command, it will create same username for two people.
Please help
Following code works except right after the insert statement i want to rst.requery to get the newly created username in in the rst recordset but it won't work. I have attached the database Access 2000, when you click on the form command, it will create same username for two people.
Please help
Private Sub Command0_Click()
Dim strSql As String
Dim StrSql1 As String
Dim strSqlUpdate As String
Dim rst As DAO.Recordset
Dim rsn As DAO.Recordset
strSql = "SELECT SamAccountName as UserName from Network UNION Select UserName From temp_user; "
strsql2 = "SELECT id_num, last_name, first_name, middle_name FROM Admission;"
Set rsn = CurrentDb.OpenRecordset(strsql2)
rsn.MoveFirst
Do While Not rsn.EOF
Dim lngStep As Integer
lngStep = 1
Set rst = CurrentDb.OpenRecordset(strSql)
rst.MoveFirst
Dim TempUserName As String
Do While Not rst.EOF
TempUserName = Left(rsn!First_name, lngStep) + rsn!Last_Name
If rst!UserName = RTrim(TempUserName) Then
lngStep = lngStep + 1
rst.MoveFirst
Else
rst.MoveNext
End If
Loop
strSqlUpdate = "INSERT into temp_user (id_num, last_name, First_name, Middle_name, UserName) VALUES ( " & rsn!ID_num & ", '" & rsn!Last_Name & " ', '" & rsn!First_name & "', '" & rsn!Middle_Name & "' , ' " & TempUserName & "');"
CurrentDb.Execute strSqlUpdate
rsn.MoveNext
Loop
Set rst = Nothing
Set rsn = Nothing
DoCmd.OpenTable "temp_user"
End Sub
Attachments
Last edited: