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

3 forms and a subform

Status
Not open for further replies.

JMM

Technical User
Feb 17, 2000
37
NZ
I have 3 forms and one subform. Form1 is for current clients, Form2 is for old clients and Form3 holds orders of both current and old clients. The subform shows some fields from the orders form and is on both Forms 1 & 2.<br><br>A click on the OrderID (on the subform) takes the user to Form3 and to that particular order.<br><br>My problem: I can't figure out how to ignore Form1 if the info is asked for from Form2 and vice versa. Here's what I've got so far but of course it doesn't work. It asks for the form that isn't open. I've tried If, Else etc and have failed.<br><br>Private Sub OrderID_Click()<br>Dim DocName As String<br>Dim LinkCriteria As String<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;DocName = &quot;frmOrders&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;LinkCriteria = &quot;[OrderID] = Forms![Form1]! [frmOrdersSub]![OrderID]&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenForm DocName, , , LinkCriteria&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;LinkCriteria = &quot;[OrderID] = Forms![Form2]![frmOrdersSub]![OrderID]&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenForm DocName, , , LinkCriteria<br>&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>Help very much appreciated.<br><br>JMM<br><br>
 
Well you might try to use the little known Active Form command:<br>Screen.ActiveForm.FormName<br><br>heres code I use to sync a subform to a main form<br>--------------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim SyncCriteria As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim f As Form, rs As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Define the from object and recordset object for the AutoCAD form<br>&nbsp;&nbsp;&nbsp;&nbsp;Set f = Forms(Screen.ActiveForm.FormName)<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rs = f.RecordsetClone<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;' define the criteria used for the sync<br>&nbsp;&nbsp;&nbsp;&nbsp;SyncCriteria = &quot;[CNUM]=&quot; & Me![CNUM]<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;' find the corresponding record in the Parts table<br>&nbsp;&nbsp;&nbsp;&nbsp;rs.FindFirst SyncCriteria<br>&nbsp;&nbsp;&nbsp;&nbsp;f.Bookmark = rs.Bookmark<br>-------------------------------------<br>What this code does is allows me to use the same subform in many different main forms.<br><br>You might use IF's to see if Form1 is active and so on.<br>Like so:<br>If Forms(Screen.ActiveForm.FormName) = &quot;Form1&quot; then<br>' Do something ........<br>End IF<br>IF Forms(Screen.ActiveForm.FormName) = &quot;Form2&quot; then<br>' Do something else........<br>End IF<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top