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

Trouble closing a Form from another Form 1

Status
Not open for further replies.

unclesvenno

Programmer
Sep 12, 2004
33
AU
Greetings,
I am trying to close a form (frmLoading) from another form (frmCostings). Here is my code within frmCosting's Form_Load event:

Code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load

    Dim rst As Recordset
    Dim Msg As String

    Set rst = CurrentDb.OpenRecordset("wDefaultAO", dbOpenDynaset)
    
    If rst.EOF Then
        
    Else
        rst.MoveFirst
        Forms!Costings!ActionOfficer = rst!ActionOfficer
        Call SetCostingList
    End If

    rst.Close
   
    Me!CostingDate = Date

    '----Add test here-----------
    ' This is the line causing me the trouble
    DoCmd.Close acForm, Forms!frmLoading
    '----Close test here---------

Exit_Form_Load:
    Exit Sub
Err_Form_Load:
    MsgBox Error$
    Resume Exit_Form_Load
End Sub

I get an error message reading "An expression you entered is the wrong data type for one of the arguments"

Also I would like to add in a test to ensure the form (frmLoading) is open before trying to close it as frmCostings is used frequently and frmLoading is only used on start up.

Thanks,
Unlce Svenno
 
How are ya unclesvenno . . . . .

You only need the form name! and quotations. Check the syntax:
Code:
[blue]    DoCmd.Close acForm, [purple][b]"frmLoading"[/b][/purple][/blue]

Calvin.gif
See Ya! . . . . . .
 
What about this ?
If CurrentProject.AllForms("frmLoading").IsLoaded Then
DoCmd.Close acForm, "frmLoading"
End If


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
unclesvenno . . . . .

Sorry . . . . forgot the last part.

In a module in the modules window copy/paste the following:
Code:
[blue]Function IsOpenForm(frmName As String) As Boolean
   Dim cp As CurrentProject, Frms As Object
   
   Set cp = CurrentProject()
   Set Frms = cp.AllForms
   
   If Frms.Item(frmName).IsLoaded Then
      If Forms(frmName).CurrentView > 0 Then IsOpenFrm = True
   End If
   
   Set Frms = Nothing
   Set cp = Nothing

End Function[/blue]
To call the function:
Code:
[blue]   Call IsOpenForm("[purple][b]YourFormName[/b][/purple]")[/blue]
The function returns [blue]True[/blue] if the form is open . . . . [blue]False[/blue] otherwise . . .

Calvin.gif
See Ya! . . . . . .
 
Whoops! hit submit too soon.

Use of the function:
Code:
[blue]   If IsOpenForm("frmLoading") then
      DoCmd.Close acForm, "frmLoading"
   End If[/blue]
You can check any form this way . . . .


Calvin.gif
See Ya! . . . . . .
 
Thanks for your help PHV and TheAceMan1, much appreciated, it has done the job
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top