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!

Opening a Form from query results

Status
Not open for further replies.

maxster

Programmer
Sep 3, 2002
45
GB
I run a query which returns the results in a sub table within a form. I need to have the ability to select one of the results from within the sub table and disply them in a new form; is this possible?

 
Taking you literally that you ahve a query datasheet as your subform, you need to do the open from the main form.

Add a button, using the wizard, to your main form(F1) which opens the second form(F2) and choose the option to find a matching record. Choose the correct matching field from F2 and any field from F1 (this will be changed later).
Complete the wizard.
Modify the code to provide the correct matching field on F2. The code should look something like this:

Private Sub Command29_Click()
On Error GoTo Err_Command29_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProducts" ' form to be opened

' productid is on F2; productno is the matching field on the subform

stLinkCriteria = "[ProductID]=" &
Me!nameofsubformcontrol.Form!ProductNo
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command29_Click:
Exit Sub

Err_Command29_Click:
MsgBox Err.Description
Resume Exit_Command29_Click

End Sub
 
Thanks.

My F1 contains the subform which has Query.GENQRY within it. I have created a form GENRESULTS which I want to populate from the sub form Query. When I add the button I get the following error "You have chosen forms that can't be linked. You must have at least one field that can be linked." The subform query and the GENRESULTS form both use the same query.

Any ideas....
 
This message suggest that you have no fields in your main form. Is that true? If so, why do have a mainform/subform and not just the subform as your main form?
 
That is correct there are no fileds within the main form. The main form consists of various functions with a central sub form displaying the results of a query. Once the results have been displayed the user wants to highlight a particular row and the then edit the information in a tabbed form rather than enter the data directly into the query results.

Any thoughts....
 
In that case you will have to juat add a button without the wizard and copy the code into the click event yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top