Results 1 to 18 of 18

Thread: [RESOLVED] form loading

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Resolved [RESOLVED] form loading

    I have a form (form1) which has a command button that loads form 2, which works fine. In addition form 3 has a command button that loads form 2 also. The problem is in form 2 i have a continue button, and i want it to go to form 4 if form 2 was laoded by form 1 or go to form 5 if loaded from form 3. I thought of counter perhaps but don;t know. Any ideas

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: form loading

    Create a Global Variable to store the name of the form you want the continue button to open.
    In F1 and F3, before you laod F2, set that variable to the correct form name.
    The continue buton can then check that variable to decide which form (F4 or F5) to open.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    i sort of get what you mean however i don't really see how the contiue button will check

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: form loading

    the following assumes that the Global variable is called "gsNextForm" and the forms are called "Form3" and "Form5" respectively.

    VB Code:
    1. Private Sub cbtnContinue_Click()
    2.     If gsNextForm = "Form3" Then
    3.         Form3.Open
    4.     Else
    5.         Form5.Open
    6.     End If
    7. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form loading

    I would recommend using a Custom Property on Form2 (thereby avoiding using a global variable):

    VB Code:
    1. ' In Form2
    2. Private fSource As Form
    3.  
    4. Private Sub cmdContinue_Click()
    5.     If fSource Is Form1 Then
    6.         Form4.Show
    7.     ElseIf fSource Is Form3 Then
    8.         Form5.Show
    9.     End If
    10. End Sub
    11.  
    12. Public Property Set OrigForm(ByVal fFrm As Form)
    13.     Set fSource = fFrm
    14. End Property
    15.  
    16. ' In Form1 & Form3
    17. Private Sub Command1_Click()
    18.     Form2.Show
    19.     Set Form2.OrigForm = Me
    20. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    cheers that it actually what i needed.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    i get a error saying object required now any idea wht is wrong

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: form loading

    Quote Originally Posted by lisa little
    i get a error saying object required now any idea wht is wrong
    On what line of code (post the entire routine as well as the line generating the error.)

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    this is on form 4
    Private fSource As Form
    Private Sub cmd1_Click()

    If fSource Is form2 Then
    form2.visable = true
    ElseIf fSource Is form3 Then
    form3.visable = true
    End If

    End Sub
    Public Property Set OrigForm(ByVal fFrm As Form)
    Set fSource = fFrm
    End Property

    To get to form 4 i have two ways via command buttons on form 3 and 2
    the code in them command buttons are:

    Unload Me
    form4.Show

    Set form4.OrigForm = Me


    when i get to form 4 and press continue it has object required run time error
    Last edited by lisa little; May 4th, 2006 at 09:34 PM.

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: form loading

    You need to set Form4.OrigForm before you unload the current form.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    still comes up with the same error if i set form4.origform before i unload current form. the error is with this as it is highlighted yellow at runtime
    If fSource Is form2

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form loading

    if you're unloading the form then the reference is going to be destroyed. Do you want to be unloading the form, because when continue is pressed it gets reloaded again.

    If that is what you want to do then try doing it this way:
    VB Code:
    1. ' In Form4
    2. Private sSource As String
    3.  
    4. Private Sub cmdContinue_Click()
    5.     If sSource = "Form2" Then
    6.         Form2.Show
    7.     ElseIf sSource = "Form3" Then
    8.         Form3.Show
    9.     End If
    10. End Sub
    11.  
    12. Public Property Let OrigForm(ByVal sFrm As String)
    13.      sSource = sFrm
    14. End Property
    15.  
    16. ' In Form2 & Form3
    17. Private Sub Command1_Click()
    18.     Form4.Show
    19.     Form4.OrigForm = Me.Name
    20. End Sub

  13. #13
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: form loading

    That makes sense, I didn't catch it because I normally hide, rather than unload forms.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  14. #14

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    'form 4 code:
    Private sSource As String

    Private Sub cmd1_Click()
    If sSource = "Form2" Then
    form2.visable = true
    ElseIf sSource = "Form3" Then
    form3.visable = true
    End If
    End Sub

    Public Property Let OrigForm(ByVal sFrm As String)
    sSource = sFrm
    End Property

    'form 2 and 3
    Unload Me
    form4.visable = true
    form4.OrigForm = Me.Name
    '
    Last edited by lisa little; May 4th, 2006 at 09:35 PM.

  15. #15
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: form loading

    Are your forms named "Form2" and "Form3" respectively? If not you need to change the comparison values in the IF statement.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  16. #16
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form loading

    I'd put the Unload Me statement after showing Form4:

    VB Code:
    1. ' In Form2 & Form3
    2. Private Sub Command1_Click()
    3.     Form4.Show
    4.     Form4.OrigForm = Me.Name
    5.     Unload Me
    6. End Sub
    You need to step through your code and check all the relevant values.

    It should work fine. Perhaps upload your project so we can have a look.

  17. #17

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    15

    Re: form loading

    i worked through it at long last. all it was having the private dec at top before another one i got, other code on form must done made it error. thanks for the great help i learn a lot.

  18. #18
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form loading

    Well I'm not really sure what you mean, but I'm glad you worked it out.

    Don't forget to mark this thread resolved if your questions been answered

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