By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Stop Duplicates being entered

P: 52
My form is for entering data about centres. Data like Centre name, number, address. i have 5 command buttons on this form
* Add new File
* Delete File
* Reset
*Clear
*Update

Im using this code on my Add new File command button to add a new file which is linked to Microsoft access.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddNew_Click()
  2. On Error GoTo LoginError
  3.  
  4. Const strValidation As String = "The Centre number should be within the range 10000 to 79999"
  5. If ((CInt(txtCentreno.Text) < 10000) Or (CInt(txtCentreno.Text) > 79999)) Then
  6.     response = MsgBox(strValidation, vbOKOnly + vbExclamation, "Invalid Input")
  7.     txtCentreno.Text = ""
  8.     txtCentreno.SetFocus
  9.  
  10.     Exit Sub
  11. Else
  12.     rsCentre.AddNew
  13.  
  14.     lstRecords.AddItem rsCentre!Centre_No
  15.     lstRecords.ItemData(lstRecords.NewIndex) = rsCentre!Centre_No
  16.  
  17.     rsCentre!Centre_No = txtCentreno.Text
  18.     rsCentre!Centre_name = txtCentrename.Text
  19.     rsCentre!Address = txtAddress.Text
  20.     rsCentre!City_Town = txtCtown.Text
  21.     rsCentre!Postcode = txtPostcode.Text
  22.     rsCentre!Tel_no = txtTelno.Text
  23.  
  24.     lstRecords.AddItem rsCentre!Centre_No & vbTab & rsCentre!Centre_name
  25.     lstRecords.ItemData(lstRecords.NewIndex) = rsCentre!Centre_No
  26. rsCentre.Update
  27.  
  28. LoginError:
  29.   If Err.Number <> 0 Then
  30.         MsgBox Err.Number & Err.Description
  31.             Err.Clear
  32.             txtCentreno.Text = ""
  33.             txtCentreno.SetFocus
  34.         End If
  35.  
  36. End If
  37. End Sub
On Access I have declared Centre Number as a primary key, when i enter data on visual basic and i repeat a centre no. that already exists it will still add the new file. it should show an error or something saying that the centre the centre number already exists or something.
How do I stop these Duplicate Centre no. (centre numbers) being entered.

Please Help
May 9 '07 #1
Share this Question
Share on Google+
2 Replies


Dököll
Expert 100+
P: 2,364
My form is for entering data about centres. Data like Centre name, number, address. i have 5 command buttons on this form
* Add new File
* Delete File
* Reset
*Clear
*Update

Im using this code on my Add new File command button to add a new file which is linked to Microsoft access.
How do I stop these Duplicate Centre no. (centre numbers) being entered.

Please Help
Hello, THEAF!

I will take a stab at this now then will look for other options for you:

(1) You should go in the design view of your table and set it to accept No duplicates

(2) You should then create a text file linked to your submit button that'll do some checking for you before VB sends data to your Access back-end

What this means is, because Access may not send you an error, or duplicate error, you must tell VB to give you an error if text or data exist in previous entry, thus in text file.

Your submit button therefore would submit to Access and a text file, local to VB. A simple If statement can be used to handle a comparison of some sort...

In a bit!

Dököll
May 10 '07 #2

Dököll
Expert 100+
P: 2,364
Hello, THEAF!

I will take a stab at this now then will look for other options for you:

(1) You should go in the design view of your table and set it to accept No duplicates

(2) You should then create a text file linked to your submit button that'll do some checking for you before VB sends data to your Access back-end

What this means is, because Access may not send you an error, or duplicate error, you must tell VB to give you an error if text or data exist in previous entry, thus in text file.

Your submit button therefore would submit to Access and a text file, local to VB. A simple If statement can be used to handle a comparison of some sort...

In a bit!

Dököll
Connecting the dots: http://www.thescripts.com/forum/thread652471.html
Jun 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.