Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching the ID fields of a form and subform

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
I have two tables (tblORC and tblTestShot). tblORC has the following fields: [ID],[Date/Time],[Item Number],[Discrete Job] and a lot more that aren't important. tblTestShot has the following fields: [ID],[Test Shot ID],[Test Shot Number] and some more fields about that "test shot".

I have a form based on tblORC with a subform based on tblTestShot. When entering in the information from the form into tblORC, I want to automatically make the [Test Shot ID] field of tblTestShot equal to the [ID] field of tblORC for all entries made into the subform.

I set up the queries so that it shows the correct "test shots" for each record.

The problem I am having is the best method of writing the correct [Test Shot ID] value into tblTestShot when based on the current [ID] value (automatically generated in the table tblORC). Here's the approach I thought of, but I am getting an error.

In the AfterUpdate event of the field entered first on my main form:

Code:
Dim db As Database, td As TableDef
    Set db = CurrentDb
    Set td = db.TableDefs![tblTestShot]
    td.Fields![Test Shot ID].DefaultValue = Me.txtID
    
    Set td = Nothing
    Set db = Nothing

It works the first time I open the form, but I finish one record and try to add another I get the following error: Error 3422: Another user has the table open, on the line td.Fields![Test Shot ID].DefaultValue = Me.txtID.

I tried closing the table before running the above code, but that does not work. I feel like I'm using the wrong approach to this problem b/c it doesn't seem very failsafe. Any suggestions would be greatly appreciated.
 
I should note that the relationship from tblORC to tblTestShot is one to many in case that wasn't clear.
 
I must be missing something, but it sounds like you want to set up a standard subform with a parent child relationship. Why can you not set in the subform properties?
link master field: ID
link child field: [test shot id]
 

Sounds like MMOOMH!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top