I am allocating a unique number to a patient and want to prevent duplicate entry before update
You would want this in the form's BeforeUpdate event: - If DCount(Expr:="*", Domain:="your form's record source", Criteria:="UniqueNumberField=" & Me.UniqueNumberField) <> 0 Then
-
Cancel = True
-
MsgBox "Number already exists"
-
End If
4 3544
You would want this in the form's BeforeUpdate event: - If DCount(Expr:="*", Domain:="your form's record source", Criteria:="UniqueNumberField=" & Me.UniqueNumberField) <> 0 Then
-
Cancel = True
-
MsgBox "Number already exists"
-
End If
Thank you very much it is working. I was using bit more complex code and giving error message type missmatched, code is as follow - Private Sub hospitalno_BeforeUpdate(Cancel As Integer)
-
-
Dim SID As Long
-
Dim stLinkCriteria As Long
-
Dim rsc As DAO.Recordset
-
-
Set rsc = Me.RecordsetClone
-
-
SID = Me.hospitalno.Value
-
stLinkCriteria = "[hospitalno]=" & "'" & SID & "'"
-
-
'Check patientdetails table for duplicate Hospital Number
-
If DCount("hospitalno", "tablepatientdetails", _
-
stLinkCriteria) > 0 Then
-
'Undo duplicate entry
-
Me.Undo
-
'Message box warning of duplication
-
MsgBox "Warning Hospital Number " _
-
& SID & " has already been entered." _
-
& vbCr & vbCr & "You will now been taken to the record.", _
-
vbInformation, "Duplicate Information"
-
'Go to record of original Hospital Number
-
rsc.FindFirst stLinkCriteria
-
Me.Bookmark = rsc.Bookmark
-
End If
-
-
Set rsc = Nothing
-
End Sub
Glad it helped. If you would select my answer as the best answer, I would appreciate it.
In future questions, it would be helpful for those of us who are trying to help you if you would give what you have tried along with any error messages (exact number and text) and the line of code that is selected when you hit debug on the error. Also, when you are posting code (VBA or SQL), please place your code in the code brackets. The button that looks like <CODE/> ( to the right of the bold, italics, underline buttons and to the left of the undo and redo buttons) will place the code tags in your post for you.
zmbd 5,501
Recognized Expert Moderator Expert
waqasi:
A few things to mention:
(-) Seth was kind enough to provide you with a coded answer; however, Bytes is not a code nor homework service. Please read the FAQ and posting guidelines before re-posting your question.
(-) Post #3: As Seth pointed out, but let me emphasize, that posting comments such as "it doesn't work" or "there's an error" does not help us help you. Instead we need the specifics as to what you expected and what happened. In the case an error, you must post the EXACT title, error message, and the error number. We must have all three parts as this help us to determine if the error is from the OS or the program.
(-) We also ask that you do the basic trouble shooting on your system. We can not perform such as our systems simply are not yours.
You should have both options set.
You should compile your code.
(-) I have also deleted a post that directly asked for code which is not normally allowed. Please refer the site FAQ and the forum sticky posting guidelines.
Sign in to post your reply or Sign up for a free account.
Similar topics
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).
...
|
by: eric.nave |
last post by:
this is a slight change to a fequently asked question around here. I
have a table which contains a "sortorder" column where a user can
specify some arbitrary order for records to be displayed in. ...
|
by: ariel81 |
last post by:
i have created a function to input data from four textboxes into a table. how do i prevent duplicate records of the same mth/Yr into the table? editing of the data in the table with reference to the...
|
by: eazyone |
last post by:
I can prevent a duplicate ID from being entered, but can't figure out how to go to that specific record. I keep getting an error message on:
Me.Bookmark = rsc.Bookmark
Its not opening and...
|
by: Arthur Dent |
last post by:
Anyone know, in VB.NET (2005) how to prevent duplicate occurrences of the
same event handler on an event?
e.g... I have some object which raises an event, and some other class which
consumes...
|
by: teser3 |
last post by:
I have my PHP inserting into Oracle 9i.
But how do I prevent duplicate record entries?
I only have 3 fields in the insert in the action page:
CODE
<?php
$c=OCILogon("scott", "tiger",...
|
by: chicago1985 |
last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
|
by: jehrich |
last post by:
Hi Everyone,
I am a bit of a hobby programmer (read newbie), and I have been searching for a solution to a SQL problem for a recent pet project. I discovered that there are a number of brilliant...
|
by: neelsfer |
last post by:
Hi
This code worked until i changed the "RaceNo" file to text from number format.
What brackets or code should i change to make it work?
This is to prevent duplicate entries.
thx for helping...
|
by: jacc14 |
last post by:
Hi
When I enter a job number i have set up the following
Dim PID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
|
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...
|
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...
|
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...
|
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,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |