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

Checking for open forlm - coding problem

Status
Not open for further replies.

surfside1

Programmer
Feb 12, 2006
209
0
0
US
Can someone tell me what is wrong with this code:
Private Sub toolstripAuctionListings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolstripAuctionListings.Click
If My.Forms.frmAuctionListings.Open() = True Then
My.Forms.frmAuctionListings.Close()
End If
My.Forms.frmAuctionListings.ShowDialog()
End Sub

I know it is the "Open" but I'm not sure what to do. I am trying to check to see if a form is open 1st before trying to open it again. The click event is for a toolstrip menu that is used in all forms in the project. I do not have any settings set for a MDI application.

I'd apprecidate any help anyone has!
 
Since you have this

My.Forms.frmAuctionListings.ShowDialog()

checking if it is open is not needed since it will never be open twice from the same application.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
I commented the lines below and received “Form that is already visible cnnot be displayed as a modal dialog box. Set the form’s visible property to false before calling showDialog and it highlights the ShowDialog statement.
Private Sub toolstripAuctionListings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolstripAuctionListings.Click
'If My.Forms.frmAuctionListings.Open() = True Then
' My.Forms.frmAuctionListings.Close()
'End If
My.Forms.frmAuctionListings.ShowDialog()
End Sub

So I added:
My.Forms.frmAuctionListings.Visible = False
before the ShowDialog and got this error:
“Form that is already displayed modally cannot be displayed as a modal dialog box. Close the form before calling showDialog.

And got the same error. Now the complete sub looks like:

Private Sub toolstripAuctionListings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolstripAuctionListings.Click
'If My.Forms.frmAuctionListings.Open() = True Then
' My.Forms.frmAuctionListings.Close()
'End If
My.Forms.frmAuctionListings.Visible = False
My.Forms.frmAuctionListings.Close()
My.Forms.frmAuctionListings.ShowDialog()
End Sub
What am I missing? Thanks for your help!
 
Uhm,...

I don't get it, the form frmAuctionlistings is already open somewhere else? Can it be opened somewhere else? or can it just be opened via this menu?

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Only from the menu. What I was testing is opening the main form, then clicking on the "Auction Listings menu button" which opens that form, then clicking on another menu button "Edit form" which opens that form(but doesn't close the Auction Listings form) then clicking on the "Auction Listings menu button" again.

I'm not sure how to close the current form before linking to another form. Plus I probably should check to see if a form is open before I close it. I went down that route also and fumbled on my If statement to check if the form was open

Does any of this make sense? Thanks!
 
So you open the mainform with show() then you open then frmauctionlistings with showdialog from the menu won mainform and then you open you click on a menu in which form, the frmaucionlistings or mainform? because if you open a form with showdialog you shouldn't be able to "go back to" / "click on" mainform.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Actually I open the main form through the Project properties "Startup Form" Later, I will change that to the Auction Listings form, but for now I'm opening the template form that contains the menu that the other forms inherit. I'm simply doing that to make sure the template operates correctly for now.

So I need logic that handles whether a form has or has not opened yet when opening them through the menu or if there are other links on the forms that link to a different form. An example of that is when the Auction Form opens it has a grid containing all the auctions. If the user clicks on one of the rows in the grid it links to the Edit form for that auction. But the edit form can also open from the menu but from there it is a new blank form.

I do appreciate how quickly you have been responding.
Thanks!
 
try using show instead of showdialog. In your case showdialog is not going to work.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
ANd then to get it to come to the foreground you need to add this

My.Forms.frmAuctionListings.ShowDialog()
My.Forms.frmAuctionListings.Select()

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top