Open Form Based on Value From Other Form

DevastatioN

Registered User.
Local time
Today, 02:44
Joined
Nov 21, 2007
Messages
242
Hello,

Slight problem getting this to work... Let's say I have tblMain and tblSub. tblMain has an ID, and tblSub has an ID2 Autonumber, ID (Linked to ID from tblMain), and then some other fields.

Form1 is based on tblMain and Form2 is based on tblSub. I have a button on Form1 that is supposed to open up Form2 based on the ID of what is on Form1. This works fine, either through Query, VB Code, or any other method I can make this work.

The problem occurs that, if there are no records yet in tblSub, I want this form to open up blank so the user can enter information, but I want the ID field in Form2 automatically populated to link to Form1.

For example, I am on Form1 and the ID is 15... I click the button to open Form2 and I see only records pertaining to ID 15... if I click "new record" I want that new record to automatically be linked to ID 15.

I tried to use VB code of:

If the ID doesn't equal the ID from Form1 then
ID = ID from Form1
End If

It says that I cannot set the value of this field however.

Any ideas, or a link to a sample database would be excellent. I imagine this is used quite a bit in inventory databases. Thanks!
 
Ok I believe I found a work around.

I will make Form2 have the tblMain ID on it and hidden, and the subform will have all the info from Table2. So when the button from Form1 opens Form2, it'll be able to find the data since it must exist for the button to be pressed. And the userwill only see the subforms and work with those, and it will look like the main form for the user, even though it is a subform.

If you are wondering why I didn't just make it a Form and Subform in the first place, instead of this elaborate form opening operation. It is because in the real scenario I'm dealing with, Form1 is actually a subform itself.
 

Users who are viewing this thread

Back
Top Bottom