473,287 Members | 1,659 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,287 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 956
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' ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.