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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link form with sub form

Status
Not open for further replies.

bhaydon

Technical User
Nov 5, 2002
82
US
I would like to be able to click on a form or preferably a record in a table and have it bring up a sub form with the same record. Is there any way to do this? Any help is appreciated.

-Brad
 
Hi,

I am assuming that by "subform" you mean a second form? Otherwise your main form's design view you should be able to use the subform wizard to insert the subform into the main form an link it with a parent/child link...
So here is the code for opening a second form from a main form:

If you are using a form then the code for your "On Click" event should look something like this:
- Change Form2Name to your second form's name
- Change UniqueID to the name of the field in your form that holds the unique id for the record
- Change UniqueID2 to fit the name of the second form's foreign unique id field
(I.E. - I have 2 tables, Table1 has a field called lastname, Table2 also has a lastname field which references the Table1 lastname)

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2Name"

stLinkCriteria = "[UniqueID]=" & Me![UniqueID2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

HTH,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Thank you for your help. I will be back tomorrow to try it out and tell you if I had success or not. Thank you for your time.

-Brad
 
For some reason it is having a problem with the last string. Any suggestions?
 
What is it doing/not doing? Any error messages? Please post your code and I'll take a look at it.

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
I am getting a runtime error '2501'

The OpenForm action was canceled

and here is my code...

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Directions"

stLinkCriteria = "[StoreNumber]=" & Me![StoreNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria

As you can figure out "Directions" is the second form I want to popup and StoreNumber is the filed that should be the same on both forms. They both share the same table, if that makes a difference. Thank you for your help, I appreciate it.

-Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top