Duplicating Data in Text Box

G Marshall

Board Regular
Joined
Dec 31, 2002
Messages
134
Hello

I have an input form linked to a table. On the form I have a text box for the user to enter a "Scheme Code Number" e.g W355. It is o.k for the user to duplicate this number in the table but if the user enters a number that has already been used I would like a message to appear on screen advising that the number has already been used with the option of entering o.k to continue or no to return to the text box.
If o.k has been clicked then I would need the cursor to move to the next text box on the form.
I realise that this would be an "on input" event procedure but I have no idea how to code the request.
Appreciate any help


Gerald
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Tanis

Active Member
Joined
Dec 8, 2002
Messages
305
Add some code to the Before Update event of the Text Box. Something like this.

If DCount("[PrimaryKey]", "TableName", "[PrimaryKey]= '" & Me![TextBoxName] & "'") = 1 Then
MsgBox "The number you have entered is a duplicate"
Me.Undo
Cancel = True
End If
 

G Marshall

Board Regular
Joined
Dec 31, 2002
Messages
134
Hi Tanis
With a little bit of tweaking this has worked perfectly, Many thanks for your help.

Gerald

(y)
 

Forum statistics

Threads
1,148,390
Messages
5,746,431
Members
424,015
Latest member
kyites

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top