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

Linking command button forms to parent form

Status
Not open for further replies.

SuePee

Technical User
Jun 10, 2003
47
US
I have a form that i plan on using to enter data. Within this form I have loaded some command buttons that call up other forms. I would like, if possible, to have the sub forms that I call up have the "SOW" (Primary key in all forms)loaded when the sub forms are opened. Is this possible?
[wavey]
 
Hi,
You can pass the key values when opening the form from the clicked event of your command button:
DoCmd.OpenForm "frmName", , ,"SOW = '" & txtSOW & "'"



HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Here is the code already there for this command button. How do I incorporate what you said into this code?

Sue

[wavey]


Private Sub Date_Modification_Click()
On Error GoTo Err_Date_Modification_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Modification"

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

Exit_Date_Modification_Click:
Exit Sub

Err_Date_Modification_Click:
MsgBox Err.Description
Resume Exit_Date_Modification_Click

End Sub
 
Hi,
Have you tested this DateModification command button? What happens? From what I can see, it opens up a form called "Modification", using the value found in "SOW".

BTW, this might be a tiny bit more efficient:
stLinkCriteria = "[SOW]= '" & Me![SOW] & "'"
You can see the first quote mark incorporated into the [SOW] section.


HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
You are right. It does open the form Modification. But I would like the form "Modification" to automatically take the "SOW" from the parent form "Contract Deliverables EF"

I am going to try the other [stLinkCriteria = "[SOW]= '" & Me![SOW] & "'"] thing you mentioned.

I have never taken a VB course, so I am not real swift at writing code. I really depend on you guys for this. And believe me I thank you very much for all your help.

sue
[wavey]
 
Sue,
I created a sample database for the newbie. It is free, and if you send an email to me, I will send it to you. In zipped format it is about 2MB. It includes a homemade security login form that is very easy to use, a homemade menu system (also very easy to use and modify), and some forms demonstrating different techniques, like how to use a form and query to pass parameters (criteria) to a report. It also has a form called Personnel Maintenance, that requires a person to be logged in, plus makes it easy to search for employees by name or SSN.

HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
You keep saying that SOW is the key and you want the child form to take the parent form's SOW value. Do you mean that you want the child form to show values for a particular SOW? An analogy would be a personnel DB with SS# as the key. You might have a button that said "show employee details" and it would show everything for a particular guy (ie, for a particular SS#).

If that is what you want, there are many easy ways to do it without VB. One obvious solution would be a text box on the parent form. The child's data source would be a query, and that query would have the text box as a criteria. The text box could be invisible if it was not something that users could understand. If you want the child to be visible when the parent isn't present, that is no problem. Just open the child an instant before you close the parent. The child will still have time to pick up the criteria for its data source.
 
Hi Steve,
I believe that Sue wanted some forms that could be called from the main form, and not "subforms". The clue to this can be found in the 2nd sentence of her initial paragraph.

HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Then the main form is like a switchboard. I would still handle the process via a macro. The first action would be to open the new form. The next action would be to close the old form. Since the new form opens before the old closes, you can pass values between them.
 
Steve,

Let me understand you. If I create a Macro to open the form then the identifier would automatically enter into the form opened by the macro? Because this is what I wanted to do. Some of the users forget to add the "SOW" to the opened form and so it is not attached to the main record when a report is requested.

When I use a sub-form, the number is automatically added, but not the forms opened by command buttons.

Sue

[wavey]
 
Yes, I think that we understand each other. You want the little form to contain the details for a certain SOW. Consequently, you think that the SOW must "pass" from the big form to the little form. There is a simpler way to achieve your goals. The basic steps are:

1) Create a macro that opens the little form, and then closes the big form. The button that opens the little form should trigger this macro.

2) Create a text box on the big form with the SOW in it. The text box can be invisible if SOW is something that the users can't understand.

3) Make the data source of the little form a query. Make a criteria for that query the value of the text box on the big form.

When the query runs, it will be able to see the text box on the big form, because the form will STILL be open. An instant later, the big form will close. My technique will not work if you want to page through multiple SOWS.

Incidentally, my technique could be implemented with VB instead of a macro. I guess my key piece of advice is: don't worry about "passing" the value. Just open the little form an instant before you close the big form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top