10 Replies - 2212 Views - Last Post: 05 September 2009 - 06:39 PM Rate Topic: -----

#1 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

[Help] Checking if a form is loaded

Posted 02 September 2009 - 06:40 PM

I'm working on a new program and one if its features includes changing a skin (ActiveSkin 4.3 + Database + Combo Control) which is working 100% but there is other forms running and I need to know how to check which ones are open (with an if statement or whatever) and then:
Unload Me
Me.Show



If somebody could please help me
Thanks!
Regards MuSSi
Is This A Good Question/Topic? 0
  • +

Replies To: [Help] Checking if a form is loaded

#2 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: [Help] Checking if a form is loaded

Posted 02 September 2009 - 08:27 PM

There is a reason they call it the "Forms Collection"
Dim F As Form
For Each F In Forms
  Debug.Print F.Name
Next F



If the form is loaded the name will be retrieved, however if code like this is used to spawn a form multiple times
Dim F As Form
Set F = New Form1
F.Show


then, you will retrieve multiple Form1's.

In the future, if you use any code like this, then you may want to use the forms tag property to keep track of which instance of a form is ...??? whatever purpose (closing, runing code, etc.). Oh yeah, you may also want a public variable for that specific form so you can keep track of how many instances there are of it.



Good Luck
Was This Post Helpful? 0
  • +
  • -

#3 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: [Help] Checking if a form is loaded

Posted 02 September 2009 - 08:47 PM

Thanks,
Dim F As Form
For Each F In Forms
  Debug.Print F.Name
Next F



Is working perfect, if it's not too much to ask how would I use the code:
Unload Me
Me.Show


on each of the form names printed in debug
Was This Post Helpful? 0
  • +
  • -

#4 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: [Help] Checking if a form is loaded

Posted 03 September 2009 - 02:43 AM

Somebody, please?? :(
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: [Help] Checking if a form is loaded

Posted 03 September 2009 - 05:13 AM

first congrats on your badge :)

i dont understand it much but :)
try this
Dim F As Form
For Each F In Forms
  Debug.Print F.Name
  F.Unload
  F.Show
Next F



good luck :)

EDIT: when you declare a form like this all the rulz for the form are avelable to it. calling public function global variable etc. :)

This post has been edited by NoBrain: 03 September 2009 - 05:14 AM

Was This Post Helpful? 0
  • +
  • -

#6 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: [Help] Checking if a form is loaded

Posted 03 September 2009 - 05:59 AM

View PostNoBrain, on 3 Sep, 2009 - 04:13 AM, said:

first congrats on your badge :)

i dont understand it much but :)
try this
Dim F As Form
For Each F In Forms
  Debug.Print F.Name
  F.Unload
  F.Show
Next F



good luck :)

EDIT: when you declare a form like this all the rulz for the form are avelable to it. calling public function global variable etc. :)


Thanks for the congratz,

I get error:
Run-time error '438':

Object doesn't support this property or method



( F.Unload )

F.Hide works but F.Show isn't working ( Form is hiding but wont unhide )

I'm messing around with it atm il edit this post if i find anything



EDITT:

I'm familiar with the Unload code and i realized its not Me.Unload and instead its Unload Me so I tried Unload F and it unloads but because all forms close the entire program closes before having an opportunity to reload, how do i get around this?

This post has been edited by MuSSi: 03 September 2009 - 06:01 AM

Was This Post Helpful? 0
  • +
  • -

#7 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: [Help] Checking if a form is loaded

Posted 04 September 2009 - 08:19 AM

Thanks for all your help,
for anyone having the same problem:
Dim F As Form
For Each F In Forms
  Debug.Print F.Name
  Shell(App.Path & "\" & App.EXEName)
  F.Unload
Next F


I put a launcher at the start to stop it from looking like a bug/glitch
Was This Post Helpful? 0
  • +
  • -

#8 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: [Help] Checking if a form is loaded

Posted 04 September 2009 - 07:01 PM

try unload f

of go to codesnippet check for closing all forms
Was This Post Helpful? 0
  • +
  • -

#9 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: [Help] Checking if a form is loaded

Posted 04 September 2009 - 10:09 PM

Yes, thava has it...
Unload F




Good Luck
Was This Post Helpful? 0
  • +
  • -

#10 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: [Help] Checking if a form is loaded

Posted 05 September 2009 - 06:53 AM

Quote

I'm familiar with the Unload code and i realized its not Me.Unload and instead its Unload Me so I tried Unload F and it unloads but because all forms close the entire program closes before having an opportunity to reload, how do i get around this?

Was This Post Helpful? 0
  • +
  • -

#11 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: [Help] Checking if a form is loaded

Posted 05 September 2009 - 06:39 PM

Okay, took me a moment to reread what you are wanting to do...
Dim OldForm As Form, NewForm As Form
For Each OldForm In Forms
  If OldForm.Name = "Form1" Then
	Set NewForm = New Form1
  ElseIf OldForm.Name = "Form2" Then
	Set NewForm = New Form2
  End If
  NewForm.Show
  Unload OldForm
Next OldForm


However, if you don't add code to keep the new forms in the same position and size then you will get some undesirable effects.



Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1