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

If Form Loaded Then......Question?

Status
Not open for further replies.

tfayer

Technical User
Aug 4, 2002
41
US
If Form Loaded Then....Question
I am working on a project that currently has 4 Forms
1. frmMain (MDIForm) - with options menu to launch other 3 forms
2. frmContactList (MDIChild = True)
3. frmCompanyList(MDIChild = True)
4. frmOptions(MDIChild = False)

The Startup Object is Sub Main: frmMain.Show

The Menu on frmMain has a command button for forms 2-4 with the following code:

Private Sub Command1_Click(Index As Integer)

Dim FormContactList As frmContactList
Dim FormCompanyList As frmCompanyList

Select Case Index
Case 0
Set FormContactList = New frmContactList
FormContactList.Show
Case 1
Set FormCompanyList = New frmCompanyList
FormCompanyList.Show
Case 2
frmOptions.Show
End Select
End Sub

frmOptions has options on 2 tabs, one for frmContactList and one for frmCompanyList. The options Are FontSize(cbo), Gridlines(chk), allow column reorder(chk). It also has 3 commnad buttons, OK Cancel and Apply.

I am using A standard Module, UserOptions, with Property Let/Get Statements for each Option and For Each Form (ie CONLST_FONTSIZE, CMPLST_FONTSIZE.......) These are Set on Startup From an ini File. The frmOptions has Private Variables m_CONLST_FONTSIZE, m_CMPLST_FONTSIZE..... that are set from the Standard Module UserOptions values. If the user hits CANCEL the form is unloaded. If the user hits APPLY the Properties in the Standard Module UserOptions are updated from the Private Variables in frmOptions. If he hits OK, the same thing as APPLY but the form closes.

I got everything working fine except that I an open frmContactList or open frmCompanyList to be updated on Apply/OK Click if they are open. I may have more than one of each open.

I tried placing this in the frmOptions cmdButton_Click(Index As Integer) Sub for the Apply Button(Index 0) and the OK Button (Index 2):

If frmContactList.Count > 0 Then
For Each FormContactList In frmContactList
frmContactList.RefreshOptions (Calls code in the user control containing the ListView1...ListView1.Refresh)
Next FormContactList
End If

The problem is that If there is no frmContactList that is open, when I click APPLY, a form opens. I place Debug.Print frmContactList.Count Within the APPLY Click Event. It prints out 1 even though there are no open forms. All that I have done in the cmdButton_Click Event of the menu Control on frmMain(MDIForm) is write Dim FormContactList As frmContactList but did not write Set FormContactList = New frmContactList Until the click event(See Above Code). Why is the frmContactList.Count = 1 Before I open a form? How can I get around all This?

Any Help will be greatly appreciated. Thanks in Advance.

 
Well,
sort of studip answer but, anyway here it goes:
In orther not to change any of your code,
try to put it yourself as 0 before you open any form.
frmContactList.Count = 0
and then open the form you want.
Sorry if this is not the case but your post is big and i read it laterally :> ===================
* Marta Oliveira *
===================
marta100@aeiou.pt
-------------------
IndraCPC
-------------------
Portugal
===================
 
Thanks for your help.

That Works but, When I Click Apply/OK while the form is open, It stil opens another instance of frmContactList. Do you have any idea why?

 
you could try the following:


Function IsLoaded(strCaption) As Boolean
Dim i

For i = 0 To Forms.Count - 1
If (Forms(i).Caption = strCaption) Then
IsLoaded = True
Exit Function
End If
Next i

End Function


Pass the caption of the form you want to load to the function. The function will return true or false depending whether the form is open or not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top