M
Memento
Hello Guys,
I'm trying to automatically create a logonname out of a filled in sur- and
lastname. I'm running into a small problem here. This is the full code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
Dim txtLogonname As String
Dim blnAddedUser As Boolean
'check if the fields are filled
If Not IsNull(txtSurName) And Not IsNull(txtLastName) Then
For i = 1 To 3
txtLogonname = LCase(Left(txtSurName, i) & txtLastName)
'check if the new logon already exists in the users table
If IsNull(DLookup("Logonnaam", "Users", "Logonnaam = '" & _
txtLogonname & "'")) Then
CurrentDb.Execute ("INSERT INTO Users (Logonnaam) " & "
VALUES (txtLogonname);"), dbFailOnError
blnAddedUser = True
Exit For
End If
Next i
If Not blnAddedUser Then
MsgBox "Couldn't create the new logon. Already existing
logonname " & _
"with the same first three letters and last name", _
vbExclamation, "Warning"
End If
Else
MsgBox "Please, fill the fields with the given name and the
lastname", _
vbExclamatoin, "Warning"
End If
End Sub
The line that gives me errors:
CurrentDb.Execute ("INSERT INTO Users (Logonnaam) " & " VALUES
(txtLogonname);"), dbFailOnError
On this line it gives me the error: "To few parameters. The expected number
is: 1".
Any ideas here?
Thanks in advance!
With regards,
Sven
I'm trying to automatically create a logonname out of a filled in sur- and
lastname. I'm running into a small problem here. This is the full code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
Dim txtLogonname As String
Dim blnAddedUser As Boolean
'check if the fields are filled
If Not IsNull(txtSurName) And Not IsNull(txtLastName) Then
For i = 1 To 3
txtLogonname = LCase(Left(txtSurName, i) & txtLastName)
'check if the new logon already exists in the users table
If IsNull(DLookup("Logonnaam", "Users", "Logonnaam = '" & _
txtLogonname & "'")) Then
CurrentDb.Execute ("INSERT INTO Users (Logonnaam) " & "
VALUES (txtLogonname);"), dbFailOnError
blnAddedUser = True
Exit For
End If
Next i
If Not blnAddedUser Then
MsgBox "Couldn't create the new logon. Already existing
logonname " & _
"with the same first three letters and last name", _
vbExclamation, "Warning"
End If
Else
MsgBox "Please, fill the fields with the given name and the
lastname", _
vbExclamatoin, "Warning"
End If
End Sub
The line that gives me errors:
CurrentDb.Execute ("INSERT INTO Users (Logonnaam) " & " VALUES
(txtLogonname);"), dbFailOnError
On this line it gives me the error: "To few parameters. The expected number
is: 1".
Any ideas here?
Thanks in advance!
With regards,
Sven