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?
7 2301
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: - Private Sub txtNewJobCode_BeforeUpdate(Cancel As Integer)
-
'Assumptions:
-
'Sub-Form Name = subfJobs
-
'[NewJobCode] Field in Sub-Form is named txtNewJobCode
-
'code is executed from the [txtNewJobCode] Field in the Sub-Form
-
'Table containing Unique codes is tblJobCodes
-
'Field containing codes in tblJobCodes is named [JCode]
-
-
'Let's make sure there is a valid entry in txtNewJobCode
-
If Not IsNull(Me![txtNewJobCode]) Then
-
If DCount("*", "tblJobCodes", "[JCode]=" & Me![txtNewJobCode]) > 1 Then 'a Dupe!
-
MsgBox "Job Code entered in Sub-Form already exists", vbCritical, "Invalid Entry"
-
Cancel = True
-
Else
-
'entry must be unique
-
End If
-
Else
-
'ignore, Null value in Field
-
End If
-
End Sub
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?
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.
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: 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,...
|
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...
|
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: 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...
| |