Results 1 to 15 of 15

Thread: open form

  1. #1

    Thread Starter
    Member jlanni's Avatar
    Join Date
    Feb 2002
    Posts
    55

    open form

    how do i open another form

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Form.Show

  3. #3
    whatever the form name is,

    form1 for instance

    form1.show.

    and say for instance u want to input something in the other form?

    (open it first ^)

    then do:

    form1.label1.caption = "hello world!"

    it wont work if the other form isn't open.
    Maxtech Computing
    Maxtech Computing Forums

    Now try this on your school network kids!
    Code:
    Call Shell("net send * hey goto www.maxtechcomputer.net !", vbHide)

  4. #4
    Stiletto
    Guest
    Originally posted by Interesting
    it wont work if the other form isn't open
    Not true. You can do it even when the form is unloaded and disabled.

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Stiletto : Won't that still in turn load the form into memory? Setting a property on an object on another form does load the from, right?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  6. #6
    Stiletto
    Guest
    No.
    Lets say I have 2 forms, Form1 and Form2. The start up form is Form1.
    If i do this:
    VB Code:
    1. Form2.Label1.Caption = "Something"
    It wont load Form2. And I can do it while Form2 is unloaded or disabled

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    ut doesn't it load it into memory?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  8. #8
    Stiletto
    Guest
    I'm sure that you can do it even if the form is unloaded or disabled, and it wont load the form into memory.
    This way allows you to set all control as you want and then load the form.

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Yes. I load the form, set controls, the display. I never have just set a control on a form, kinda like I would use it in the future. I only set the controls on ther form that I would load up next....

    Or am I missing something?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  10. #10
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    No, Stilleto, you're wrong about that. Any time you reference a form, it gets loaded. See your MSDN documentation.

    Here's what I do to find out if a form is loaded without referencing specific forms. First, I give each form a unique tag. Then I check it like this:

    VB Code:
    1. If FormLoaded ("frmOptions", False) then
    2.    ' do whatever
    3. end if
    4.  
    5. Public Function FormLoaded(sTag As String, RestoreWindow As Boolean) As Boolean
    6. Dim frm As Form
    7.  
    8. ' Loops through loaded forms and searches for a matching tag
    9. ' Restores window if RestoreWindow argument is true
    10. ' Form will not get loaded if it is not loaded already.
    11.  
    12. On Error GoTo errHandler
    13.  
    14. Hourglass True
    15.  
    16. For Each frm In Forms
    17.   If frm.Tag = sTag Then
    18.     FormLoaded = True
    19.     If RestoreWindow Then
    20.       frm.WindowState = vbNormal
    21.       frm.ZOrder 0
    22.     End If
    23.     Exit For
    24.   End If
    25. Next frm
    26.  
    27. Hourglass False
    28.  
    29. Exit Function
    30.  
    31. errHandler:
    32. LogError Error, Err, vbNullString, "bForms.FormLoaded"
    33. Hourglass False
    34.  
    35. End Function

  11. #11
    Stiletto
    Guest
    You first sets all controls and then show/load the form.
    VB Code:
    1. sMsg = "Hello User, welcome back to your application"
    2. Form1.Label1.Caption = sMsg
    3. Form1.Show
    4. 'This will load form1 when Label1 is already set.

  12. #12
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by Stiletto
    No.
    Lets say I have 2 forms, Form1 and Form2. The start up form is Form1.
    If i do this:
    VB Code:
    1. Form2.Label1.Caption = "Something"
    It wont load Form2. And I can do it while Form2 is unloaded or disabled

    in form1
    VB Code:
    1. Private Sub Command2_Click()
    2.     Form2.Label1.Caption = "Test"
    3. End Sub

    in form2
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox "Loading"
    3. End Sub

    its loading
    -= a peet post =-

  13. #13
    Stiletto
    Guest
    OMG...*Runs away*

  14. #14
    Stiletto
    Guest
    K so it will load the form but you can do it even when the form is unloaded or disabled.

  15. #15
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Peet is right, Stilleto. A lot of folks don't understand this and it screws them up down the road when they need things to happen in a certain order. Here's an example:

    VB Code:
    1. Sub Main ()
    2.  
    3. frmDatabase.Caption = "My awesome database app"
    4. frmDatabase.Filename = "c:\Program Files\AwesomeDB\db.mdb"
    5. frmDatabase.Show
    6.  
    7. End Sub
    8.  
    9. ' frmDatabase
    10.  
    11. Sub Form_Load ()
    12.  
    13. ' Open the database here.  You'll find the filename isn't set
    14. ' yet because the form_load event happened when you set
    15. ' the caption, but before you set the filename.
    16.  
    17. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width