473,399 Members | 3,401 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,399 software developers and data experts.

checking for duplicate values between subform and query data

I have a main form that has combo boxes linked to a query that
outputs the results of the query to text boxes on a subform. We
have a job code (naming) convention here that assigns the first 2
digits based on the location selected from the combo box, the next 2
from the department, and so on...

I've set up the subform to requery itself any time data from the
combo boxes on the main form is changed, and that is working fine.
The problem I'm having is with writing code to check the NewJobCode
field on the subform against the main table list of existing codes
(called ExistingCodes.JCode) for duplicates.

I want to have an error message pop up if duplicates are found.
Any ideas?
Oct 26 '07 #1
7 2301
ADezii
8,834 Expert 8TB
I have a main form that has combo boxes linked to a query that
outputs the results of the query to text boxes on a subform. We
have a job code (naming) convention here that assigns the first 2
digits based on the location selected from the combo box, the next 2
from the department, and so on...

I've set up the subform to requery itself any time data from the
combo boxes on the main form is changed, and that is working fine.
The problem I'm having is with writing code to check the NewJobCode
field on the subform against the main table list of existing codes
(called ExistingCodes.JCode) for duplicates.

I want to have an error message pop up if duplicates are found.
Any ideas?
Enter similar code in the BeforeUpdate() Event of the [NewJobCode] Field on your Sub-Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtNewJobCode_BeforeUpdate(Cancel As Integer)
  2. 'Assumptions:
  3.   'Sub-Form Name = subfJobs
  4.   '[NewJobCode] Field in Sub-Form is named txtNewJobCode
  5.   'code is executed from the [txtNewJobCode] Field in the Sub-Form
  6.   'Table containing Unique codes is tblJobCodes
  7.   'Field containing codes in tblJobCodes is named [JCode]
  8.  
  9. 'Let's make sure there is a valid entry in txtNewJobCode
  10. If Not IsNull(Me![txtNewJobCode]) Then
  11.   If DCount("*", "tblJobCodes", "[JCode]=" & Me![txtNewJobCode]) > 1 Then     'a Dupe!
  12.     MsgBox "Job Code entered in Sub-Form already exists", vbCritical, "Invalid Entry"
  13.      Cancel = True
  14.   Else
  15.     'entry must be unique
  16.   End If
  17. Else
  18.   'ignore, Null value in Field
  19. End If
  20. End Sub
Oct 27 '07 #2
Thanks for the info. Unfortunatley I can't seem to get it to work. Do I need to make any declarations after the Sub header? Do I need to create any functions to get this to work?
Oct 29 '07 #3
ADezii
8,834 Expert 8TB
Thanks for the info. Unfortunatley I can't seem to get it to work. Do I need to make any declarations after the Sub header? Do I need to create any functions to get this to work?
Do I need to make any declarations after the Sub header? Do I need to create any functions to get this to work?
You need none of the above. You do, however, have to substitute your Table Name, Field Name, Sub-Form Name, and the Sub-Form Field Name with you own values. If you are really stuck, and it is practical, you can send the Database to me as an Attachment and I'll have a look at it. Should it get to this point, and you are willing to do this, just let me know.
Oct 30 '07 #4
I'd really, really appreciate that. What email address should I use for you? I see that the interface on this page doesn't allow for attachments.



You need none of the above. You do, however, have to substitute your Table Name, Field Name, Sub-Form Name, and the Sub-Form Field Name with you own values. If you are really stuck, and it is practical, you can send the Database to me as an Attachment and I'll have a look at it. Should it get to this point, and you are willing to do this, just let me know.
Oct 31 '07 #5
ADezii
8,834 Expert 8TB
I'd really, really appreciate that. What email address should I use for you? I see that the interface on this page doesn't allow for attachments.
I'm sending you my Private E-Maill address in Private Message. Send an E-Mail to that address with the Database as an Attachment.
Oct 31 '07 #6
Adezii,

Thank you so, so much for your help! The code works great!!I would not have been able to figure this out on my own.
Thanks again!

I'm sending you my Private E-Maill address in Private Message. Send an E-Mail to that address with the Database as an Attachment.
Nov 2 '07 #7
ADezii
8,834 Expert 8TB
Adezii,

Thank you so, so much for your help! The code works great!!I would not have been able to figure this out on my own.
Thanks again!
You are quite welcome. Normally, I would insist that the results be posted in this Thread for all to see, but in your unique circumstance, it would not make much sense without having the actual Database in front of you.
Nov 2 '07 #8

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

Similar topics

1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
9
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or...
2
by: Pablo | last post by:
Hello, there, I have a table tblData which has pharmacy data. The table has following fields: ClaimNum, LineNum... The ClaimNum has claim number which is 12 characters. LineNum is NULL. The...
0
by: cmd | last post by:
Hi, I have a query based on Table-A which populates most of the pages of a tab control. On two of the pages, however, I would like to have fields from Table-B. There's too many fields in this...
2
by: mavmavv | last post by:
I have a Form where I have created a duplicate record button, no problem... The subform is where my problem lies. The subform displays data matching the mainform's ID, these two values are...
9
by: leah | last post by:
I will explain this situation using a scenario. Let's assumed that i'm working on a library system where i need a loan form that will only show books that are available for loan. In this case, this...
1
by: VinArt | last post by:
MS Acc 2003, XP Thank you in advance for any help. I have tables called "Makeup" and "Lines". Each makeup can have multiple lines. Goal is to create a new "makeup" with identical "lines"...
3
by: 6afraidbecause789 | last post by:
Kudos to anyone who can explain this one--how to duplicate a group of continuous records in a subform for use in a new subform PK ID. The 2 entry fields (combo boxes) in the subform are RoleID and...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
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: 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
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
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,...
0
isladogs
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 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.