473,399 Members | 3,832 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.

Using a Subform to Create and/or Link a Record Depending on Whether it Already Exists

4
I'm sorry this is so long. I've edited a couple of times now, and cut it by 1/3 but haven't come up with a way to shorten it more without losing important bits.

I don't even know what to search for, so I'm sorry if this has been answered. I don't think I'm trying to do something too "out there" but on the other hand I can't find any examples for what I am trying to do (either saying it can't be done or here is how it is done).

The setup:
The user is creating (or modifying) an Internal Incident for a product that was out of specification. Each product has a unique lot number. Lots are in their own table, so the form for creating an internal incident has a subform for entering the lot numbers. This is working normally.

The problem:
If the user tries to use a lot number that already exists, it states that the record cannot be added because a duplicate is being created in a unique index.

First attempt at a solution:
I changed the lot number from a text box to a combo box. The user could still enter new lot numbers (so long as they didn't exist yet), but if they wanted to link to an existing lot either the drop-down was blank or, if there were lots to select, it not only didn't update the other fields to match the chosen lots it still gave the unique index error and promptly messed up the information for the hapless lot chosen (which I've finally at last realized relates to the bound column choice, but isn't the true issue).

Second attempt at a solution:
I wandered into the world of .Seek and .NoMatch and promptly was in way over my head. I can certainly get it to trigger whether or not the lot number exists, but have no clue what to do past that point.

I changed the lot number box from a bound control to an unbound control. On LostFocus, it tests to see if the control is Null, and if it isn't null, focus goes to the Product combo box. The macro there for GotFocus is where the Seek is performed, and the .NoMatch is set. But now I'm stuck with two problems: what to do with the matching information AND how to link the lot number back to the internal incident. In other words, I think I just blew up the complexity by orders of magnitude and I'm peering over the edge of the abyss.

What I really want to do:
This doesn't fit into searches either here or for Google, because I can't think of a simpler way to word it. What I want is for the user to simply type in the lot number for their new (or updated) internal incident, and when they go to the next control, if the lot already exists, populate the subform with the existing information and link that existing lot to the internal incident. If the lot doesn't exist, I want it to behave as I'm used to a subform doing, and create the new record for the lot, linked to the internal incident.

I don't want or expect anyone to hand me the answer, unless that answer is "No, you need a different approach because you are seriously breaking subforms." I just want to get a suggestion as to which direction to look, or if the answer really is through Seek and (as with about everything else in this project) I'm running up a brick wall because I'm a VBA newbie.

No code is provided because I don't have any that has come even remotely close to doing what I want.
Dec 12 '14 #1
1 1358
Rabbit
12,516 Expert Mod 8TB
You don't need a subform. If I understand correctly, one lot can have many products. In a situation like this, you use a drop down that lists the existing lots. But you set the combo box to allow items not in the list so they can type other values. And you use the Not In List Event to add new values.

Subforms are meant for the reverse situation. Where you have one parent record and you want to add many child records.
Dec 12 '14 #2

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

Similar topics

2
by: Deano | last post by:
Thanks for the replies to my previous post. So while I'm on a roll here's another plea for help. I simply need the code for a button on the main form that will create a new record in the...
6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
8
by: bob | last post by:
I am writing some code to create new tables in a SQL database. However, I don't want to try to create a table if it already exists. How can I test beforehand to see if a particular named table...
2
by: kkleung89 | last post by:
Basically, here's what's happening with the program. I have a table of Customers and a table of Pets, with the latter containing a field linking it to its customer of ownership. I have a form...
3
by: byeung | last post by:
Hi, I am trying to check if a particular record already exists in an Access database through Excel vba code. Through code obtained at another forum, I got the following: ...
4
by: colonial | last post by:
I was wondering if what I'm trying to do in Access XP and 2003 is possible. I've looked at countless templates and samples and havn't seen anything like what I want to do to be able to construct it....
4
gundarap
by: gundarap | last post by:
Hello all, I'm working on minidom. My goal is to see whether an element already exists in the xml file before adding. I was using getElementsByTagName() to check weather the element already exists....
1
by: dwasler | last post by:
Try every thing I know to remove this alias I know there been other posting I read each one none seem to work. Thank You DLWasler dwasler@yahoo.com OS Window db2 V 8.2.X
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
5
Seth Schrock
by: Seth Schrock | last post by:
I have a form with a subform. To save time, I have set several of the main form controls to have default values so that I don't have to edit them most of the time. The subform is often the first...
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
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
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...
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.