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

IIf statement to check if form is open

Status
Not open for further replies.

Hump

Technical User
Jan 30, 2002
3
CA
I have two forms; Sales Entry and Customer Info. If I am in Sales Entry, I have a command button to open Customer Info to enter a new customer on the fly. When I close the Customer Info form, I need to refresh the Sales Entry form, so I inserted a "Refresh" in the "On Close" event in the Customer Info form. This works fine, but when the Customer Info form is opened independently of the Sales Entry form and then closed, the code wants to refresh the Sales Entry form which of course is closed. SO, Is it possible to use an IIf statement to check if the Sales Entry form is open before doing a refresh? If so, what would be the syntax?

Thanks in advance.
 
The clean way to do this would be to have the refresh occur in the code for the commandbutton_click on your first form, not in your second form. Is there a reason you can't do that?
Rob
[flowerface]
 
I have a combo box to select a customer and in order to update it, I have to perform a refresh after updating the customer form, not as I open it.

Thanks.
 
But why not have

sub commandbutton_click()
CustomerInfo.show
..code to refresh sales entry form
end sub

In other words, show the userinfo form, then refresh the sales entry form. (I'm not sure what code/command you are using to refresh the form, hence the undefined line).
Rob
[flowerface]
 
This may not be the way to win the battle, but it might solve your specific question on how to test to see if a form is open.

The Forms Collection contains only forms that are open. Ones that are stored on disk, but not open have to bee accessed via another method. The following function can pass you a True/False condition to tell you whether your form is open:


Sub Is_Form_Open(str_NameOfForm as String) as Boolean

Dim frm_MyForm as Form

On Error Resume Next

Set frm_MyForm = Forms(str_NameOfForm)

If Err <> 0 Then
Is_Form_Open = False
Else
Is_Form_Open = True
End If

Set frm_MyForm = Nothing

End Sub


Hope this helps!

--- Tom
 
Tom,

That's the little jewel that I was looking for! All I needed was: If form is true then refresh...works like a charm.

Many Thanks and Merry Christmas!
Hump.
 
Sometimes, the simplier things are the best ones.

You are welcome ... anytime! Who know, I may need help the next time. --- Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top