473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Duplicate username entry problem

Hi,

Basically I have a problem with registering to my quiz system. I had
borrowed some code from an existing program but I just do not know why
it doesn't work.

If (txtUsername = "" Or txtPassword = "") Or (txtFirstName = "" Or
txtLastName = "") Then
MsgBox "Please complete all the fields", vbCritical = vbOKOnly,
"Incomplete Login Details"
txtFirstName.SetFocus
Else

Set rs = rs.Open("SELECT * FROM Login"), ......
'add new account to login database
With rs
.AddNew
!UserName = Trim(txtUsername)
!Password = Trim(txtPassword)
!FirstName = Trim(txtFirstName)
!LastName = Trim(txtLastName)
On Error GoTo duplicate
.Update
MsgBox "Congratulations! You can use the system now.",
vbInformation, "Details entered"
duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.SetFocus
Exit Sub
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If

Well it's not that it doesn't work, it bypasses the error message. If
I enter a duplicate username, it gives me a success message rather
than an error. However, it does run the .cancelupdate function. I am
catering for an error in the Err = 3022 if statement, which is an
error code for duplicate entry of a primary key.

Please someone tell me what am I doing wrong here and how to rectify
the problem, I'll be really appreciated.
Jul 17 '05 #1
3 3932

"Mohammed Mazid" <ka******@hotmail.com> wrote in message
news:7c**************************@posting.google.c om...
Hi,

Basically I have a problem with registering to my quiz system. I had
borrowed some code from an existing program but I just do not know why
it doesn't work.

If (txtUsername = "" Or txtPassword = "") Or (txtFirstName = "" Or
txtLastName = "") Then
MsgBox "Please complete all the fields", vbCritical = vbOKOnly,
"Incomplete Login Details"
txtFirstName.SetFocus
Else

Set rs = rs.Open("SELECT * FROM Login"), ......
'add new account to login database
With rs
.AddNew
!UserName = Trim(txtUsername)
!Password = Trim(txtPassword)
!FirstName = Trim(txtFirstName)
!LastName = Trim(txtLastName)
On Error GoTo duplicate
.Update
MsgBox "Congratulations! You can use the system now.",
vbInformation, "Details entered"
duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.SetFocus
Exit Sub
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If

Well it's not that it doesn't work, it bypasses the error message. If
I enter a duplicate username, it gives me a success message rather
than an error. However, it does run the .cancelupdate function. I am
catering for an error in the Err = 3022 if statement, which is an
error code for duplicate entry of a primary key.

Please someone tell me what am I doing wrong here and how to rectify
the problem, I'll be really appreciated.


Just a wild guess. When you create the database are you disallowing null
fields? If so, it is possible when the add statement is executed that you
are getting a different error (3315 = zero length fields) or even 3421 =
datatype mismatch (i.e. alpha in num field) if you incorrectly specify the
field.

Best thing to do is put a break point and trace it so you can know EXACTLY
the error code that was raised.
Jul 17 '05 #2
It looks to me like you have two separate problems:

One is that the error 3022 is not being raised, therefore your On Error
never trips. That I can't help you with.

Your other problem is with program flow. On Error you would jump to your
"duplicate:" label, which is proper... but the way it's written, you go
there even if there's no error! Try changing this:
On Error GoTo duplicate
.Update
MsgBox "Congratulations! You can use the system now.",
vbInformation, "Details entered"
duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.SetFocus
Exit Sub
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If
to this:
On Error GoTo duplicate
.Update
MsgBox "Congratulations! You can use the system now.",
vbInformation, "Details entered"
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If

duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.SetFocus
Exit Sub

etc.
Jul 17 '05 #3
One last thing: indentation is your friend! Use it wisely, and your
program logic becomes MUCH clearer!
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jtw | last post by:
I need to update a statistics table through out the day. I would like to insert the first data sampling of the data, then update the existing record for the rest of the day. The problem is that I...
3
by: David | last post by:
Hi, I have a page which lets me select a user from a list by checking a check box next to the specific user and pressing a submit button. The Check box holds the value = 'UserID'. A new form...
1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
0
by: mmazid | last post by:
I would like to know how to prevent entering the same data as a primary key to an MS Access database and return with an error message confirming the data already exists in ASP.Net (VB.Net). ...
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
3
by: deepaks85 | last post by:
Dear Sir, I have setup a SQL database with PHP. Whenever I am trying to insert the data into my database it gives me error : 'Duplicate entry for key 2'. Please help me sir. I am sending you...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.