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

Return to previous form.

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
I have an Add/Edit for that has a couple of buttons for lookups that call other forms.

One button for FileNumberLookup and another for TrackingNumberLookup.

When the user clicks on the button a user prompt is presented (stored procedure) and the user enters the criteria. Then the lookup form is presented with the requested data. When the user clicks on the "close" button I need it to return to the form that the user came from.

Here is what I had been using.

Code:
Private Sub btnBoxNumberLookup_Click()
    DoCmd.OpenForm "frmFileNumberLookup", acNormal, , , acFormEdit, acWindowNormal, Me.Name
End Sub

Code:
Private Sub CloseForm_Click()
    If fIsLoaded("frmTrackingTable") = False Then
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm ("frmTrackingTable")
        Else
        DoCmd.Close acForm, Me.Name
        DoCmd.SelectObject acForm, "frmTrackingTable"
    End If
End Sub
But this would mean that I would have to modify the code for each close button on each form. I was hoping for a better way to do this.


Thanks

John Fuhrman
 
How about opening the Lookup form in the Dialog mode?

DoCmd.OpenForm "frmFileNumberLookup", acNormal, , , acFormEdit, acDialog, Me.Name
 
you can pass the name of the calling form using the openArgs argument of the docmd.openform

then simply
Code:
Private Sub CloseForm_Click()
    If fIsLoaded(me.openargs) = False Then
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm (me.openargs)
        Else
        DoCmd.Close acForm, Me.Name
        DoCmd.SelectObject acForm, me.openargs
    End If
End Sub
I believe the above code can be simplified to

DoCmd.Close acForm, Me.Name
DoCmd.OpenForm (me.openargs)
DoCmd.SelectObject acForm, me.openargs

I believe the rest is superfluous.
If a form is already open and you "reopen" it just goes to that form, and reselecting it is not detrimental either.
 
How would I make this a function or sub?

Code:
Option Compare Database

On Error GoTo err_handler

Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim frmName As String

frmName = frmCurrentForm.Name

    Select Case frmName
        Case "Menu_Main"
            If fIsLoaded("Menu_Main") = False Then
                DoCmd.Close
                DoCmd.OpenForm ("Menu_Main")
            Else
                DoCmd.Close
                Forms![Menu_Main].Visible = True
            End If
        
        Case Else
            DoCmd.Close acForm, Me.Name
            DoCmd.OpenForm (Me.OpenArgs)
            DoCmd.SelectObject acForm, Me.OpenArgs
        End Select

endit:
Exit Sub

err_handler:
    Select Case Err
        Case 2501
            'Do Nothing
        Case Else
            MsgBox _
            "An unexpected error has been detected" & Chr(13) & _
            "Description is: " & Err.Number & " , " & Err.Description & Chr(13) & _
            vbCrLf & "Please note the above details before contacting support"
    End Select
Resume endit

Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top