Making a form work like a subform

G

Guest

When I create a subform on a main form the wizard goes through some steps one
of them being the control?/field? that will link the two forms. So every
time I add a record to the subform it automatically populates its record with
that field. Now I have a button that opens a complete new form which I want
to have one of it's field?/controls? populated the same way, while allowing
the user to enter the rest of the information. How do I get the button to do
that?

Main Table:tblCases
Secondary Table: tblSAR
Main form: frmCaseMain
Second Form: frmSAR
Linking Field/Control(same for both forms and all tables associated): CaseNum

The idea is that for each record in the main table I will have multiple
records in the table that frmSAR is based on, affectionately known as tblSAR.
I already can make a data sheet that shows all the records in tblSAR that
have the same CaseNum as those in tblCases but it is just a snippet of the
information. I want the user to be able to click a button to open frmSAR so
they can enter more detailed information as well as a memo field.

I thought I had a decent grasp syntax but in this case I am lost.

Deepest thanks for any help.
 
A

Albert D.Kallal

The only real thing you need in this new form you opened up is to tell it
how to set the link child field

The best event to use is the on-insert event in this 2nd form (frmSAR in
your example).

So, lets assume we are in form 1 (main table tblCases - frmCaseMAin)

We have button on this form..and want to open the child form. our code would
be

me.Refresh
docmd.openform "frmSAR",,,"CaseNum = " & me!CaseNum

in the forms on-insert event, we go

me!CaseNum = forms!frmCaseMain!CaseNum

That is all you should need. I would suggest you make the frmSAR model....

If casenum is a text type field..and not a number type field, then you must
use quotes

docmd.openform "frmSAR",,,"CaseNum = '" & me!CaseNum & "'"

The above might be hard to see...so with extra spaces (that you have to
remove) we have

docmd.openform "frmSAR",,,"CaseNum = ' " & me!CaseNum & " ' "
 
G

Guest

Wow, thank you so much that helped a heck of a lot got it working that way
now. I don't suppose there is a way to make frmCaseMain reload/update all
subforms within it or individual ones? I tried doing this in the On Got
Focus event of frmCaseMain: "Me.sbfSAR.Form.Refresh" and then I tried
"Me.sbfSAR.Requery" but neither of them would update the subform with the
newly added information from frmSAR.

-CaseNum is always a text field in all forms and tables
-sbfSAR is the subform within frmCaseMain that displays all the SAR info
matching by CaseNum.
 
A

Albert D.Kallal

Two choices:

In the on-close event of the 2nd form..you could requery the previous form.

or, better yet...use:


on-focus will not work.however, on-activate will work..and is likely the
best event to use. just put in a

me.Requery

Furhter, as mentioend..you should make the 2nd (child form) model..so the
user is forced to close this form to return to the previous one...
 
G

Guest

Woo, thank you so much that worked perfectly. And I have almost all my forms
modal but I disable the normal close button because I want to create a cancel
button that would not save the records the user may have entered. Again,
THANK YOU!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top