473,394 Members | 1,802 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,394 software developers and data experts.

validation rules

116 100+
I am wanting to prevent duplicates if 2 fields already exist. I therefore set primary keys on both the fields. This works but it is only after completing a line that it tells me that i have duplicate records. I have tried to set up a recordset and it works to prevent a duplicate if one of the fields is already in there but i cant seem to compare 2 fields. This is my code but i want to add the second field.

Expand|Select|Wrap|Line Numbers
  1.  Dim PID As String
  2. Dim stLinkCriteria As String
  3. Dim rsc As DAO.Recordset
  4. Set rsc = Me.RecordsetClone
  5. PID = Me.JobNo.Value
  6. stLinkCriteria = "[jobno]=" & "'" & PID & "'"
  7. 'Check StudentDetails table for duplicate StudentNumber
  8. If DCount("jobno", "tbl_jobheader", _
  9. stLinkCriteria) > 0 Then
  10. 'Undo duplicate entry
  11. Me.Undo
  12. 'Message box warning of duplication
  13. MsgBox "Warning Job Number " _
  14. & PID & " already exists in database.", _
  15. vbInformation, "Duplicate Information"
  16. 'Go to record of original Student Number
  17.  
  18. End If
  19. Set rsc = Nothing
  20.  
am i over complicating things

Many thanks

Christine.
May 26 '10 #1

✓ answered by ChipR

You've got the right idea with DCount. You can get rid of the rsc stuff, and change your criteria string to include both fields.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[jobno] = """ & PID _
  2.  & """ AND [otherField] = """ & OtherStringValue & """"

2 960
ChipR
1,287 Expert 1GB
You've got the right idea with DCount. You can get rid of the rsc stuff, and change your criteria string to include both fields.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[jobno] = """ & PID _
  2.  & """ AND [otherField] = """ & OtherStringValue & """"
May 28 '10 #2
jacc14
116 100+
@ChipR
Many thanks for this. Problem solved.
May 29 '10 #3

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

Similar topics

1
by: Dalan | last post by:
For some apparent reason I have been unable to structure a piece of code on the BeforeUpdate event on a form that has 3 fields which I need to set validation rules. I would appreciate anyone's...
0
by: ssmith86 | last post by:
I have created a DAP linking to only one table. Several of the fields on the table have validation rules. The only time my message boxe comes up is when I am finished inputting data on the DAP...
7
by: Tom | last post by:
How do I set up the following Validation Rules in a table: 1. Two chars - both must be digits(0-9) 2. Three characters - first character must be a letter 3. 6 characters - all must be...
5
by: Jeremy | last post by:
I have a vb .net 2003 app that uses access 2k as a backend. The main table has some validation rules (legacy stuff brought forward inadvertantly, and now we're stuck with 'em). The problem is,...
3
by: tsnyder | last post by:
I need to set a validation rule for a field so that it looks at all other fields to make sure that field is true.
7
by: sesling | last post by:
I have a form that has several text boxes where the operator can enter data. I want to place some validation rules around what the operator can enter. In one box I want the number to be at least...
6
by: JHNielson | last post by:
I have a form with a drop-down box and 4 other text boxes Owner, Name, Date, State. I would like to limit it so that the user can only enter data in those boxes if the drop down equals "Purchase"?...
3
by: babamc4 | last post by:
Hi Experts, I have just completed designing a new DB and my boss has asked me to put some complicated (I think!) validation rules on to it. My table is below: 1. Index - Autonumber 2....
7
jinalpatel
by: jinalpatel | last post by:
I have two tables Mainfirm and Subfirm. I have everything ready. Now I am entering validation rules like as below in my form fields to protect the tables from bad data. But when I try to enter...
2
by: DrSporkeh | last post by:
Hai everyone, i need some help :o basically im trying to set some validation rules for an 'employees' table. firstly i've set it to you have to be 16 to work here under 'Date Of Birth' ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.