|
-
Aug 15th, 2012, 12:32 PM
#1
Thread Starter
Junior Member
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
-
Aug 15th, 2012, 12:38 PM
#2
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.
-
Aug 15th, 2012, 02:30 PM
#3
Thread Starter
Junior Member
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.
 Originally Posted by DataMiser
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.
-
Aug 15th, 2012, 03:08 PM
#4
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
-
Aug 15th, 2012, 03:17 PM
#5
Thread Starter
Junior Member
Re: opening form(s) from listbox double Click
 Originally Posted by DataMiser
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
-
Aug 15th, 2012, 05:32 PM
#6
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
-
Aug 20th, 2012, 07:48 AM
#7
Thread Starter
Junior Member
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.
 Originally Posted by DataMiser
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
-
Aug 20th, 2012, 05:40 PM
#8
Frenzied Member
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
-
Aug 20th, 2012, 05:41 PM
#9
Frenzied Member
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
-
Aug 21st, 2012, 09:20 PM
#10
Thread Starter
Junior Member
Re: opening form(s) from listbox double Click
 Originally Posted by firoz.raj
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.
-
Aug 22nd, 2012, 01:57 PM
#11
Re: opening form(s) from listbox double Click
 Originally Posted by jstinnett
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|