Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a New User

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I have a run time error 2447: Invalid use of .(dot)or ! operator or invalid parenthese.
I have a yellow hightligth on the section of &quot;While UserName <> &quot;&quot;

This is my code:
Private Sub cmdAdd_Click()
Dim strSysAdminFlag
If IsNull(Me.txtUserName) Then
MsgBox &quot;Please enter a username&quot;, vbOKOnly, &quot;Entry Error!&quot;
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox &quot;Please enter a password&quot;, vbOKOnly, &quot;Entry Error!&quot;
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox &quot;Please confirm the entered password&quot;, vbOKOnly, &quot;Entry Error!&quot;
Exit Sub
End If
If txtPassword = txtPasswordConf Then
DoCmd.GoToRecord , , acFirst
While UserName <> &quot;&quot;
If txtUserName = UserName Then
MsgBox &quot;User already exists. System cannot add user.&quot;, vbOKOnly, &quot;Entry Error!&quot;
UserName = &quot;&quot;
UserName.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNext
Wend
Dim Msg, Style, Title, Response
Msg = &quot;This will add user &quot; & txtUserName & &quot; to the system. Are you sure you want to add this user?&quot; ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = &quot;Add User&quot; ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else: Exit Sub
End If
Else
MsgBox &quot;Passwords do not match&quot;, vbOKOnly, &quot;Entry Error!&quot;
txtPassword = &quot;&quot;
txtPasswordConf = &quot;&quot;
txtPassword.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNewRec
UserName = txtUserName
Password = txtPassword
MsgBox &quot;User &quot; & txtUserName & &quot; has been added.&quot;, vbOKOnly, &quot;Update success&quot;
txtUserName = &quot;&quot;
txtPassword = &quot;&quot;
txtPasswordConf = &quot;&quot;
UserName.Visible = False
Password.Visible = False
DoCmd.GoToRecord , , acNewRec
txtPasswordConf.Enabled = False
txtUserName.SetFocus
cmdAdd.Enabled = False
cmdDisregard.Enabled = False
txtUserName.SetFocus
End Sub
 
Hi,

You didn't sopecify which line it was erroring on, however, it seems like this line is the culprit:

'You probably wanted to clear textbox.

UserName = &quot;&quot;
UserName.SetFocus


UserName is a variable correct? If so it won't have a method setfocus unless it is an object representing a textbox. I think you are missing the &quot;txt&quot;.

Have a good one!
BK
 
I'm real confused where you are getting UserName from. You are using good naming convention for Textboxes so I assume it is not a textbox, but then you also are using acNext navigation inside the loop and later on you use txtUserName as a control so it could possible be a textbox or even a bound field name for a textbox. I've never understood why users develop an application to handle logons when Access has two ways of managing this same thing.

My best guess is that you are using a table to store usernames and passwords and the form that contains the cmdAdd button is bound to the table. You then navigate to the first record and search through each of the other records until you either come to the end of the records or find a matching username.

Try this as an alternative:
cmdAdd_AfterUpdate
Dim strUsername As String
strUsername = Nz(DLookup(&quot;[UserName]&quot;, &quot;tblUsernames&quot;, [UserName]='&quot; & Me.txtUsername & &quot;'&quot;), &quot;&quot;)
If strUsername <> &quot;&quot; Then
' Hey you have found a matching username so the
' one in txtUsername is a duplicate
' This can only work because the current record
' has not updated the table.
End If
End cmdAdd_AfterUpdate

Or, another means would be to make the username the Primary Key field for the table. Then, when the user attempted to enter a duplicate, you would get an error which could be trapped and send a notice back to the user that is is a duplicate.

Or, another means would be to use the RecordsetClone and not move to the individual records but navigate using the disconnected recordset.

----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
BlackKnight,

The problem line is #17 While UserName <> &quot;&quot;
 
BlackKnight,

The problem line is #17
While UserName <> &quot;&quot;
 
I had this problem. The resolution was what the data that was in the textbox. When I had the error that textbox had an incorrect reference to another control and the value was #NAME. When I correct the problem I no longer got the error 2447.
 
or try this
while isnull(username) = false &quot;What a wonderfull world&quot; - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top