7
72185
Well right now I am generating a "username" and then checking to see
if the "username" is unique or not. I have a table set up with 1000s
of usernames so I am trying to make sure that the same one does not
get used over. So with that in mind I am letting the end user
generate their name and then I want it to go through the table and see
if its unique and if it is unique to send a message saying "its
unique" and if not then to add a "A" or "B" to the end of it depending
how many times the name has been used. I am having trouble looking up
the name in the table. I just keep getting the same name I have in
the textbox although its a unique name. Here is what I have so far.
strfirstname = [Forms]![ADD_EDIT_RECORD_FRM]![FIRSTNAME]
strmiddlename = [Forms]![ADD_EDIT_RECORD_FRM]![MIDDLENAME]
strlastname = [Forms]![ADD_EDIT_RECORD_FRM]![LASTNAME]
[Forms]![ADD_EDIT_RECORD_FRM]![usernametextbox] = Left(strfirstname,
1) & Left(strmiddlename, 1) & Left(strlastname, 6)
strusername = usernametextbox.Value
'MsgBox "Username: " & strusername, vbOKOnly, "Invalid Search
Criterion!"
Dim strusernameRef As String
Dim strSearch As String
'Check txtSearch for Null value.
If IsNull(Me![usernametextbox]) Or (Me![usernametextbox]) = ""
Then
MsgBox "Please enter First Name, Middle Initial and Last
Name!", vbOKOnly, "Invalid Search Criterion!"
Me![usernametextbox].SetFocus
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
Me.USERNAME = DLookup("[username]", "[IMPORT]",
"[usernametextbox]='" & [Forms]![ADD_EDIT_RECORD_FRM]!
[usernametextbox] & "'")
DLookup("CatID", "IMPORTegories", "[USERNAMEgFieldName] = '"
&Me.Item & "'")
DoCmd.ShowAllRecords
DoCmd.GoToControl ("usernametextbox")
DoCmd.FindRecord Me!USERNAME
strSearch = usernametextbox.Text
intAsciiValue = 65
usernametextbox.SetFocus
strusernameRef = USERNAME
usernametextbox.SetFocus
Do Until strusernameRef <> strSearch
If strusernameRef = strSearch Then
MsgBox "Username: " & strSearch & " Is Already In
Use. A New Username Will be Provided", , "Choose another Name!"
usernametextbox.SetFocus
usernametextbox = ""
strusernameRef = strSearch & Chr(intAsciiValue)
MsgBox "New username name is: " & strusernameRef, ,
"Choose another Name!"
usernametextbox = strusernameRef
intAsciiValue = intAsciiValue + 1
'If value not found sets focus back to txtSearch and shows
msgbox
Else
MsgBox strusernameRef & " - Username Is Unique.", ,
"Username Unique!"
PERSONELNUM.SetFocus
End If
Loop
End Sub
Any help is appreciated!
if the "username" is unique or not. I have a table set up with 1000s
of usernames so I am trying to make sure that the same one does not
get used over. So with that in mind I am letting the end user
generate their name and then I want it to go through the table and see
if its unique and if it is unique to send a message saying "its
unique" and if not then to add a "A" or "B" to the end of it depending
how many times the name has been used. I am having trouble looking up
the name in the table. I just keep getting the same name I have in
the textbox although its a unique name. Here is what I have so far.
strfirstname = [Forms]![ADD_EDIT_RECORD_FRM]![FIRSTNAME]
strmiddlename = [Forms]![ADD_EDIT_RECORD_FRM]![MIDDLENAME]
strlastname = [Forms]![ADD_EDIT_RECORD_FRM]![LASTNAME]
[Forms]![ADD_EDIT_RECORD_FRM]![usernametextbox] = Left(strfirstname,
1) & Left(strmiddlename, 1) & Left(strlastname, 6)
strusername = usernametextbox.Value
'MsgBox "Username: " & strusername, vbOKOnly, "Invalid Search
Criterion!"
Dim strusernameRef As String
Dim strSearch As String
'Check txtSearch for Null value.
If IsNull(Me![usernametextbox]) Or (Me![usernametextbox]) = ""
Then
MsgBox "Please enter First Name, Middle Initial and Last
Name!", vbOKOnly, "Invalid Search Criterion!"
Me![usernametextbox].SetFocus
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
Me.USERNAME = DLookup("[username]", "[IMPORT]",
"[usernametextbox]='" & [Forms]![ADD_EDIT_RECORD_FRM]!
[usernametextbox] & "'")
DLookup("CatID", "IMPORTegories", "[USERNAMEgFieldName] = '"
&Me.Item & "'")
DoCmd.ShowAllRecords
DoCmd.GoToControl ("usernametextbox")
DoCmd.FindRecord Me!USERNAME
strSearch = usernametextbox.Text
intAsciiValue = 65
usernametextbox.SetFocus
strusernameRef = USERNAME
usernametextbox.SetFocus
Do Until strusernameRef <> strSearch
If strusernameRef = strSearch Then
MsgBox "Username: " & strSearch & " Is Already In
Use. A New Username Will be Provided", , "Choose another Name!"
usernametextbox.SetFocus
usernametextbox = ""
strusernameRef = strSearch & Chr(intAsciiValue)
MsgBox "New username name is: " & strusernameRef, ,
"Choose another Name!"
usernametextbox = strusernameRef
intAsciiValue = intAsciiValue + 1
'If value not found sets focus back to txtSearch and shows
msgbox
Else
MsgBox strusernameRef & " - Username Is Unique.", ,
"Username Unique!"
PERSONELNUM.SetFocus
End If
Loop
End Sub
Any help is appreciated!