entering data into a form (Access 2010)

dave1234aust

New member
Local time
Today, 18:18
Joined
Sep 1, 2016
Messages
4
Hi,

I have created a form that allows users to enter data rather than have them enter using the Navigation pane, don't groan it's how it was running up until last week.

I want to restrict users from entering data into the form and then at the last field being told by Access that the first field (primary key) is a duplicate. Is there a way that I can use a message box, or when data is put into the first field and the user tabs to the next field that Access will trigger an error message.

I would have thought this would be automatic, but it lets me enter everything until the last entry and then stops it saving - which yes is good that the primary key is doing its thing.

Thank you for reading and any assistance would be really appreciated.

Dave
 
I assume from your description that the User is entering the PK into a bound textbox. If so and assuming your PK is a numberfield then in the BeforeUpdate event of the textbox put something like;

Code:
If Dcount("YourPKField","YourTableName","[YourPKField] = " & Me.YourtextBoxName ) > 0 Then
     Msgbox "Duplicate Value!"
     Cancel = True
End IF
 
And if the PK is defined as Text (as they sometimes are, when it's AlphaNumeric, for example)

Code:
If Dcount("YourPKField","YourTableName","[YourPKField] = '" & Me.YourtextBoxName & "'" ) > 0 Then
   Msgbox "Duplicate Value!"
   Cancel = True
End If
Linq ;0)>
 
Minty / missinglinq

Perfect - just what I needed. I should have mentioned the pk was a text field (duly noted for next time).

Thank you both for your time and effort.

Dave
 

Users who are viewing this thread

Back
Top Bottom