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!

Trying to return focus to calling form

Status
Not open for further replies.

planetdrouin

Technical User
Dec 29, 2001
36
US
I am trying to call a form from many different sources and return to the calling form. I am trying to use the openargs function but to no avail. My code is as follows:

Called form: frmClientOfficeIn
Calling form (this example): frmOutstandingCheques
(Code from Calling Form)

Private Sub Details_Click()
On Error GoTo Err_Details_Click
gstrWhereClient = "[InOutID] = " & Me!InOutID
DoCmd.OpenForm FormName:="frmClientOfficeIn", _
WhereCondition:=gstrWhereClient, _
OpenArgs:="frmOutstandingCheques"
Forms!frmClientOfficeIn.SetFocus
Forms!frmClientOfficeIn!AccountsMenu.Visible = False
Forms!frmClientOfficeIn!MainMenu.Visible = False
Forms!frmClientOfficeIn!CloseLedger.Visible = True
Exit_Details_Click:
Exit Sub
Err_Details_Click:
MsgBox "No information selected to view.", vbExclamation, "NDR Software 1.0"
Resume Exit_Details_Click
End Sub



(Code on Called Form)

Private Sub CloseLedger_Click()
DoCmd.Close acForm, Me.Name
Forms(Me.OpenArgs).SetFocus
End Sub

I get a run-time error that the expression you entered refers to an object that is closed or does not exist. If I replace the line:

Forms(Me.OpenArgs).SetFocus

With

Forms("frmOutstandingcheques").SetFocus

My code works. But I would rather use the openargs function as I will be calling the form from many different forms. Any help is greatly appreciated.

Lawrence


 
Not 100% sure, but I think if you were to move the setfocus onto the called form's Close event you would be alright.

I used
Code:
  Dim strFormName As String
  strFormName = Me.OpenArgs
  DoCmd.OpenForm strFormName
on the Close event without problem, but moved it onto a command button with Docmd.Close and ran into the same problem you described.

I believe that when DoCmd.Close runs, everything in the CLose event fires as part of that code.

Please let me know if this works for you.


HTH





John

Use what you have,
Learn what you can,
Create what you need.
 
John (Boxhead)

You are right about the DoCmd.Close function. Not sure if this is exactly what you meant, but by simply moving the Forms(Me.OpenArgs).SetFocus line prior to the DoCmd.Close line fixed it all.

Thanks for your help.

Lawrence
 

An accepted approach is to simply place the name of the calling form in the "Tag" propertyt of the called form. When the Called form exits, it cjhecks the tag property. If the tag property has the name of a form, it just shows that form and closes itself.

It is also common - in this approach- to open the second form as modal, to keep the focus on the "sub task" until it is complete.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top