Solved

MS Access issue with linked records

Posted on 2014-02-25
4
230 Views
Last Modified: 2014-02-25
Hi,

Can anyone help with this more than probably simple query!? I've have a few tables (example included) and a few forms built in Access. I'm looking a user to be able to input information into a form and an appropriate record created for the data inputted.

I've got tbl_Items and tbl_Location:tbl_Itemstbl_LocationRelationship
The User form allows a record to be created in tbl_Items if the location exists. If it does not exist, it throws an expected error:error.

I understand that because the relevant record doesn't exist in tbl_location, Access isn't allowing it, but is there anyway to avoid this, alert the user and have an option for the appropriate record to be created in tbl_Location at the same time??

Stuck for ideas on how I could implement this, so any advice is much appreciated.

John
0
Comment
Question by:-johnb
  • 2
  • 2
4 Comments
 
LVL 84
ID: 39886133
Not really. The Parent record must exist in order for the Child to be created - sorta like real life :) .

Most times this is represented by a Mainform/Subform setup, with tblLocation as the source of the Mainform, and tblItems as the source of the Subform. The user would select the desired Location (or enter a new one), and then enter the Items associated with that Location.

You could force this, perhaps, but it's not a good way to work with related data. If a record in tblLocation is TRULY required before an item in tblItems can exist, then you need to enforce that relationship.

If that is NOT the case - that is, if an item in tblItems CAN exist without being tagged to a record in tblLocation - then you have problems with your structure, and you need to review that.
0
 

Author Comment

by:-johnb
ID: 39886193
Unfortunately it's definitely needed for other purposes in the db. Each record in tbl_locations has several fields that are used for other purposes - similar to - locating a desk, in an office, on a floor, in a particular building - there would only ever be one end desk, but that desk id may exist on another floor or another building if you get my meaning.

The user would be presented similar options to that scenario through the use of dependant  drop downs, but unfortunately as not all systems are linked, the record may not always exist, so I can't depend on it.

I was hoping to add the ability for the user to create that record - there and then - maybe using VBA, before carrying on with the remaining data entry...
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39886473
If you use the Mainform/Subform setup, you'd have that ability immediately. The user would not be able to create a record in the subform unless they had either selected an existing record in the Mainform (i.e. a location record), or entered a new record.

Using a query to drive a form like this is not the right way to do things. The only way you'd get that to work would be to use unbound fields (where you capture data from the user and write it to the database using SQL/VBA) or use Temporary tables (same scenario - you capture data in the temp tables, then use SQL/VBA to write it to the correct tables). Either of these methods can be difficult to implement, and are prone to orphaned records, unnecessary duplication, etc etc.

In other words, unless you have a very valid reason for doing so, you should be use the mainform/subform method for handling related records.
0
 

Author Comment

by:-johnb
ID: 39887172
Thanks Scott, I'll take that advice on board and look at implementing the form/subform method if I can't brush up my VBA skills first!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
A Function to parse a text string 4 34
Access Crosstab Query with Multiple Values 4 32
Calculation in Access 5 26
Field naming convntions - MS Access 7 26
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question