Results 1 to 10 of 10

Thread: opening form(s) from listbox double Click

  1. #1
    Junior Member
    Join Date
    Nov 11
    Posts
    19

    opening form(s) from listbox double Click

    Ok I have ran into a problem that I need help with. I have searched but cant find anything that I need.
    Ok my problem is. I have a 2 forms. form1 is full screen and I have a list box and command button. when i click the command button I have it to ask 2 questions and put the answers as the caption on form2 and also into the listbox when I click the command button again (on form1) it asks the questions and opens another blank instance of form2. All this I have working fine so far my problem lies with when I double click the listbox on the form1 I want it to make form2 with the right caption on it to the front (make it Visible). I can't figure it out or find it anywhere. Any help would be great

    thanks in advance
    james

  2. #2
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: opening form(s) from listbox double Click

    Code:
    Form2.Caption="Whatever you want"
    Form2.Show
    If you are talking about the second instance then you would use the name for the second instance rather than form2 also if talking about a second instance it needs to be defined with a scope that is accessible to the routine.

    In other words if in your command click event you had

    Code:
    Dim MyNewForm2 as New Form2
    Then MyNewForm2 would not be a valid reference outside that sub routine

    You would need to dim it at the top under the declarations or in as public in a module to access it outside a routine.

  3. #3
    Junior Member
    Join Date
    Nov 11
    Posts
    19

    Re: opening form(s) from listbox double Click

    ok lets say I have a listbox with say 3 things in it
    eg
    Jstinnett @ 11th st
    someone @ 12th st
    someone else @ 15th st
    (each one has a form opened with all their info typed in so far in them. The forms are named Jstinnett @ 11th St, someone @ 12th St, ect)
    I want to be able to double click on the listbox eg Jstinnett @ 11th st and have it make the form with that caption visible so I can edit it without making all of them visible.



    Quote Originally Posted by DataMiser View Post
    Code:
    Form2.Caption="Whatever you want"
    Form2.Show
    If you are talking about the second instance then you would use the name for the second instance rather than form2 also if talking about a second instance it needs to be defined with a scope that is accessible to the routine.

    In other words if in your command click event you had

    Code:
    Dim MyNewForm2 as New Form2
    Then MyNewForm2 would not be a valid reference outside that sub routine

    You would need to dim it at the top under the declarations or in as public in a module to access it outside a routine.

  4. #4
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: opening form(s) from listbox double Click

    You could loop through the forms collection and check the caption of each until you find the one you are looking for

  5. #5
    Junior Member
    Join Date
    Nov 11
    Posts
    19

    Re: opening form(s) from listbox double Click

    Quote Originally Posted by DataMiser View Post
    You could loop through the forms collection and check the caption of each until you find the one you are looking for
    thats what I have been trying to do but I can't get it working. I have been trying
    dim FC as string
    FC = list2.text

    if form2.caption = FC then
    FC.show
    end if

    And

    dim FC as string
    FC = list2.text

    if form1.caption = FC then
    form2.FC.show
    end if

    and a few more but nothing I try seems to work

  6. #6
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: opening form(s) from listbox double Click

    You are trying to reference a form by name. the name Form2 applies only to the original instance each instance has a different name.
    You are not using a loop nor are you checking the forms collection.

    Code:
    Dim frm As Form
    
    For Each frm In Forms
       Debug.Print frm.Caption
    Next

  7. #7
    Junior Member
    Join Date
    Nov 11
    Posts
    19

    Re: opening form(s) from listbox double Click

    ok when I use this code it puts all the forms into the list box (which I am already doing) including the login form(main form) which I dont need in there. It still doesnt help me with being able to show the form that I need to when I double click them in the list box.

    Quote Originally Posted by DataMiser View Post
    You are trying to reference a form by name. the name Form2 applies only to the original instance each instance has a different name.
    You are not using a loop nor are you checking the forms collection.

    Code:
    Dim frm As Form
    
    For Each frm In Forms
       Debug.Print frm.Caption
    Next

  8. #8
    Frenzied Member
    Join Date
    Jan 09
    Location
    Watch Window(Shift+f9)
    Posts
    1,431

    Re: opening form(s) from listbox double Click

    ok when I use this code it puts all the forms into the list box (which I am already doing) including the login form(main form) which I dont need in there. It still doesnt help me with being able to show the form that I need to when I double click them in the list box.
    i am not sure what you want .but if you want to exclude login form .you need to check with if condition .like as follows.
    Code:
    Dim frm As Form
    
    For Each frm In Forms
       Debug.Print frm.Caption
    
    if frm.name="Frmlogin" then
       'Do what you want '
    End if
    Next

  9. #9
    Frenzied Member
    Join Date
    Jan 09
    Location
    Watch Window(Shift+f9)
    Posts
    1,431

    Re: opening form(s) from listbox double Click

    ok when I use this code it puts all the forms into the list box (which I am already doing) including the login form(main form) which I dont need in there. It still doesnt help me with being able to show the form that I need to when I double click them in the list box.
    i am not sure what you want .but if you want to exclude login form .you need to check with if condition .like as follows.
    Code:
    Dim frm As Form
    
    For Each frm In Forms
       Debug.Print frm.Caption
    
    if frm.name="Frmlogin" then
       'Do what you want '
    End if
    Next

  10. #10
    Junior Member
    Join Date
    Nov 11
    Posts
    19

    Re: opening form(s) from listbox double Click

    Quote Originally Posted by firoz.raj View Post
    i am not sure what you want .but if you want to exclude login form .you need to check with if condition .like as follows.
    Code:
    Dim frm As Form
    
    For Each frm In Forms
       Debug.Print frm.Caption
    
    if frm.name="Frmlogin" then
       'Do what you want '
    End if
    Next
    the main form is full screen and every new from is opened and moved to the front with the caption added to the list box and then when another form is need the first is minimized and a new form is showed so and and so forth but what I need and trying to figure out is how to bring the form that is double clicked in the list box to the front so i can add more info to it. when I start the new forms they are named frmMain but the captions are all different so I have to find a way to tell what form is what.

  11. #11
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: opening form(s) from listbox double Click

    Quote Originally Posted by jstinnett View Post
    ok when I use this code it puts all the forms into the list box (which I am already doing) including the login form(main form) which I dont need in there. It still doesnt help me with being able to show the form that I need to when I double click them in the list box.
    Actually no that code does not put anything in a list box, it simply shows you how to get the caption of all loaded forms, here it prints those captions to the debug window.

    You need to use your head a little, all you have to do is look at the item which was clicked then use a loop like I showed you to loop through the forms collection until you find the one that matches and then do what you need to do with that form.

Posting Permissions

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