M
Memento
Ok Guys,
I've gotten some help already here, which was very helpfull. What am i doing
here:
* I'm taking txtSurName and txtLastName and trying to automatically create a
login name. (the first letter of the surname, followed by the lastname, one
word, lowercase --> if that one exists: take the first two letters of the
surname, followed by lastname, up to three letters of the surname max)
* It needs to check wheter or not a loginname exists, based on that, it will
add one more letter of the surname if a login should exist.
* If a login does not exist, it writes the value to the table Users, in the
field "logonnaam". That's it.
! The problem: it keeps jumping to the forelast Else: "Couldn't create the
new logon. Already existing logon name with the same first three letters and
last name", although the login name doesn't exists.
Any suggestions?
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
Dim rec As Recordset
Dim newlogonname As String
If Not IsNull(txtSurName) And Not IsNull(txtLastName) Then ' you check if
the fields are filled
i = 1
newlogonname = LCase(Left(txtSurName, i) & txtLastName)
Do While IsNull(DLookup("logonnaam", "Users", "logonnaam = '" & newlogonname
& "'")) 'check if the new logon already exists in the users table
i = i + 1
If i = 4 Then Exit Do
newlogonname = LCase(Left(txtSurName, i) & txtLastName)
Loop
If i < 4 Then
Set rec = CurrentDb.OpenRecordset("select * from users", dbOpenDynaset)
rec.AddNew
rec![logonnaam] = newlogonname
rec.Update
rec.Close
Else
MsgBox "Couldn't create the new logon. Already existing logon name with
the same first three letters and last name", 48, "Warning"
End If
Else
MsgBox "Please, fill the fields with the given name and the last name",
48, "Warning"
End If
End Sub
I've gotten some help already here, which was very helpfull. What am i doing
here:
* I'm taking txtSurName and txtLastName and trying to automatically create a
login name. (the first letter of the surname, followed by the lastname, one
word, lowercase --> if that one exists: take the first two letters of the
surname, followed by lastname, up to three letters of the surname max)
* It needs to check wheter or not a loginname exists, based on that, it will
add one more letter of the surname if a login should exist.
* If a login does not exist, it writes the value to the table Users, in the
field "logonnaam". That's it.
! The problem: it keeps jumping to the forelast Else: "Couldn't create the
new logon. Already existing logon name with the same first three letters and
last name", although the login name doesn't exists.
Any suggestions?
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
Dim rec As Recordset
Dim newlogonname As String
If Not IsNull(txtSurName) And Not IsNull(txtLastName) Then ' you check if
the fields are filled
i = 1
newlogonname = LCase(Left(txtSurName, i) & txtLastName)
Do While IsNull(DLookup("logonnaam", "Users", "logonnaam = '" & newlogonname
& "'")) 'check if the new logon already exists in the users table
i = i + 1
If i = 4 Then Exit Do
newlogonname = LCase(Left(txtSurName, i) & txtLastName)
Loop
If i < 4 Then
Set rec = CurrentDb.OpenRecordset("select * from users", dbOpenDynaset)
rec.AddNew
rec![logonnaam] = newlogonname
rec.Update
rec.Close
Else
MsgBox "Couldn't create the new logon. Already existing logon name with
the same first three letters and last name", 48, "Warning"
End If
Else
MsgBox "Please, fill the fields with the given name and the last name",
48, "Warning"
End If
End Sub