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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if username already is in use

Status
Not open for further replies.

Frihi

Programmer
Jun 24, 2001
48
0
0
CH
I have an input textbox (txtUser) and a dbList (XUser) with the names of the already registered users. Now if a new user wants to register I want to check if the name he wants to use is already in use, in order to advice him to choose another name. The data is stored in an Acces database and the control is a common data Control. That works fine, so the only problem at the moment is the check-code.

Public Sub Continue_Click()
If TxtUser <> &quot;&quot; _
And txtFirstName <> &quot;&quot; _
And txtName <> &quot;&quot; _
And txtPassword.Text = txtConfirm.Text Then

' here would be the check-code, something like select
' case or do while ...

MsgBox &quot;OK&quot;, 0, &quot;&quot;
Data1.Recordset.Update
Krit = &quot;User='&quot; & XUser & &quot;'&quot;
frmSFlash.Data1.Recordset.FindLast Krit
frmSFlash.Show
Unload Me
End If
End Sub

Can anybody help?

Thanks

Fritz
 
i know nothing about databases.... but you said a dblistbox... so i can only give you partial help and a wild guess... here i go..

i dunno i guess the stored user names are stored in a listbox of some sort... is what im going by..


For i = 0 to dblistbox.ListCount - 1
if dblistbox.List(i) = txtUser then
MsgBox &quot;User already exists&quot;
Exit Sub
end if
Next i

'code to do the stuff if it doesnt exist


i hope this helps in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Create a query:

Select * from RegisteredUsers where FirstName = txtFirstName.text and TextName = txtName.text
If the recorset returns a value >=1 then
Tell the person to name is in use
exit sub
End if

 
Well, it took a while. Unfortunately it didn't work with your advices. For some reason the ListCount property did not work - I don't know why. And with the query I had problems on the syntax. But finally I found a way to do it and I think it might be useful for somebody, so here it is:

Public Sub Continue_Click()

Dim DB As Database
Dim Rec As Recordset
'Open Database:
Set DB = OpenDatabase(&quot;C:\Path&quot;)
'Open Recordset:
Set Rec = DB.OpenRecordset(&quot;Tablename&quot;)

If txtUser <> &quot;&quot; _
And txtFirstname <> &quot;&quot; _
And txtName <> &quot;&quot; _
And txtPassword.Text = txtConfirm.Text Then
'Check if all fields have an input text and if the
'password-confirmation is ok.
Data1.Recordset.FindFirst &quot;User = '&quot; & txtUser & &quot;'&quot;
'Check if the Username is in use already.
If Data1.Recordset.NoMatch Then
MsgBox &quot;OK&quot;
Rec.AddNew
Rec.Fields(&quot;User&quot;) = txtUser
Rec.Fields(&quot;Firstname&quot;) = txtFirstname
Rec.Fields(&quot;FName&quot;) = txtName
'Field cannot be &quot;Name&quot;
Rec.Fields(&quot;Passwort&quot;) = txtPassword
Rec.Update
'Save the new record.
Else
MsgBox &quot;Invalid Username&quot;
txtUser = &quot;&quot;
txtUser.SetFocus
Exit Sub
End If
' stuff to do if everything is ok...
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top