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

Popup product form that shows selected record.

Status
Not open for further replies.

banco

Technical User
Jul 9, 2002
11
US
Hello everyone,

Here it goes..

I have an orders form like the one in Northwind. I put a button on the form that will show a popup form that shows details of the selected product in the orders subform. I have included the following code on the button, but it promps me for the product's ID instead of getting it automatically for me.

Can some one tell me what might be the problem?

Private Sub Popup_button_Click()
On Error GoTo Err_Popup_button_Click

Dim stDocName As String
Dim strLinkCriteria As String

stDocName = "ProductsPopup"
strLinkCriteria = "ProductID = Forms!Orders!OrdersSubform!ProductID"
DoCmd.OpenForm stDocName, , , strLinkCriteria

Exit_Popup_button_Click:
Exit Sub

Err_Popup_button_Click:
MsgBox Err.Description
Resume Exit_Popup_button_Click

End Sub

Thank you in advance... To guess is cheap
To guess wrongly is expensive
Tell me, I may remember
But involve me and I'll understand.

 
Hi

I assume your product is in a sub form and your button on the main form, from your existing code:

strLinkCriteria = "ProductID = Forms!Orders!OrdersSubform!ProductID"

You need

strLinkCriteria = "ProductID = " & Forms!Orders!OrdersSubform.FORM.ProductID

or if ProductID is a string:

strLinkCriteria = "ProductID = '" & Forms!Orders!OrdersSubform.FORM.ProductID & "'"

I am aso assuming, that you have called your subform control, the same name as the form it contains.

Hope this helps
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Hello KenReay,

Your first assumption is correct, but can you elaborate more in your last assumption?

"I am also assuming, that you have called your subform control, the same name as the form it contains."

Is it that the button needs to have the same name as the popup form, please elaborate a little bit more...

Is that why I'm getting that enter parameter box?

Thank you,

banco


To guess is cheap
To guess wrongly is expensive
Tell me, I may remember
But involve me and I'll understand.

 
Hi

No not the button.

On a mainform, you place a subform control, that subform control (like any other control) has a name. Within that subform control you place a form. The form is identified by the .SourceObject property of the subform control (an can incidentally be changed at runtime).

So for example:

Debug.Print Forms!Categories![Product List].SourceObject

will print the name of the form contained within the subform control [Product List] which in turn is on the form Categories.

Many (Most?) people call the subform control by the same name as the form it contains. This in itself is not a problem, but the syntax of some commands requires the subform control name and others require the form name my point was that if you have NOT called them both by the same name then you need to be aware of this subtle difference

so (from Access Help:

"Type the identifier for the form that contains the subform, followed by the name of its subform control, the . (dot) operator, and the Form property. For example, the following identifier refers to the Orders Subform subform on the Orders form:

Forms![Orders]![Orders Subform].Form"

It is important to note here that ![Orders Subform]. is the name of the subform CONTROL, not the form, the FORM property gives access to the form, and controls within the (sub) form can then be addressed by tagging the !ControlName onto the FORM so

Forms![Orders]![Orders Subform].Form!MyControl

Hope that makes my point clear.
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top