 |
 |

11-04-2003, 12:34 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 31
|
|
Noob question- how to get the same control to run in multiple forms
|
I have a project with multiple forms, and I would like the same listbox to appear in separate forms. How would I link them together or make it so that the same listbox and data appeared in multiple forms?
Thanks for the help!
|
|

11-04-2003, 01:24 AM
|
 |
Junior Contributor
|
|
Join Date: Aug 2002
Location: London
Posts: 238
|
|
Quote: Originally Posted by johnh I have a project with multiple forms, and I would like the same listbox to appear in separate forms. How would I link them together or make it so that the same listbox and data appeared in multiple forms?
Thanks for the help!
The simplest idea would to have a listbox control on each form and to then populate the listbox with the same list as the previous listbox
something like:
Code:
Private Sub Form2_FormLoad()
Dim iCount AS Integer
With Form1
For iCount = 1 To .Listbox1.ListCount
ListBox2.AddItem = .Listbox.Index(iCount)
Next iCount
End With
End Sub
Note: Listbox1 is on Form1 and Listbox2 is on Form2
Hope this helps 
|
__________________
"The more I practice, the luckier I get." - Gary Player
|

11-04-2003, 01:42 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 31
|
|
Still have an error
|
Thanks for the help. I typed in your code, but I am still getting the error, "wrong number of arguments or invalid property assignment."
The part that is highlighted is
Private Sub Form_Load() and .Index
Here is my code
Private Sub Form_Load()
Dim iCount As Integer
With frmGrades
For iCount = 1 To .lstStudents.ListCount
lstStudent.AddItem = .lstStudents.Index(iCount)
Next iCount
End With
End sub
Do you know what could be giving me the error?
Thanks a lot for your help!
|
|

11-04-2003, 01:43 AM
|
 |
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
|
|
change this ... For iCount = 1 To .lstStudents.ListCount
to this ....
Code:
For iCount = 0 To .lstStudents.ListCount -1
|
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
|

11-04-2003, 01:44 AM
|
 |
Senior Contributor
|
|
Join Date: Aug 2003
Location: Tomarria
Posts: 905
|
|
Instead of
Code:
For iCount = 1 To frmGrades.lstStudents.ListCount
do this:
Code:
For iCount = 0 To frmGrades.lstStudents.ListCount - 1
//EDIT of course i was a minute late.....  
|
__________________
...leben ohne sinn...
|

11-04-2003, 06:56 AM
|
 |
Junior Contributor
|
|
Join Date: Aug 2002
Location: London
Posts: 238
|
|
 Whoops, Sorry for the blups.
I blame it on a rough night at the pub.

|
__________________
"The more I practice, the luckier I get." - Gary Player
|

11-04-2003, 08:17 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 31
|
|
I don't think that is what is giving me the error
|
The listbox on my first form is named lstStudents, and the name of the listbox on the third form lstStudent. Here is my code on the third form.
Private Sub Form_Load()
Dim iCount As Integer
With frmGrades
For iCount = 0 To .lstStudents.ListCount - 1
lstStudent.AddItem = .lstStudents.Index(iCount)
Next iCount
End With
The same part of the code is being highlighted as before, I think there is a problem with this line
lstStudent.AddItem = .lstStudents.Index(iCount)
Do I need to change .lstStudents.Index(icount) to something else?
Thanks a lot for the help!
|
|

11-04-2003, 10:05 AM
|
|
Junior Contributor
|
|
Join Date: Oct 2003
Location: So. Calif
Posts: 342
|
|
I suspect that form1 objects are out of scope.
Try this..
Code:
For iCount = 0 To [B]Form1[/B] .lstStudents.ListCount - 1
lstStudent.AddItem = [B]Form1[/B].lstStudents.Index(iCount)
Next iCount
|
|

11-04-2003, 11:00 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 31
|
|
Still can't get it to work
|
Thanks for the replies and the help. However, The program still won't work. The error message "Wrong number of arguments or invalid property assignment" is still coming up, and the same areas are being highlighted. Do I need do declare something as a string in a module?
Here is my code:
Private Sub Form_Load()
Dim iCount As Integer
With frmGrades
For iCount = 0 To frmGrades.lstStudents.ListCount - 1
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
Next iCount
End With
Thank you all for the help
|
|

11-05-2003, 02:18 AM
|
 |
Junior Contributor
|
|
Join Date: Aug 2002
Location: London
Posts: 238
|
|
Quote: Originally Posted by johnh Thanks for the replies and the help. However, The program still won't work. The error message "Wrong number of arguments or invalid property assignment" is still coming up, and the same areas are being highlighted. Do I need do declare something as a string in a module?
Here is my code:
Private Sub Form_Load()
Dim iCount As Integer
With frmGrades
For iCount = 0 To frmGrades.lstStudents.ListCount - 1
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
Next iCount
End With
Thank you all for the help
Sorry, I think this is my mistake again.
instead of :
Code:
lstStudent.AddItem = frmGrades.lstStudents.Index(iCount)
takeout the =
Code:
lstStudent.AddItem frmGrades.lstStudents.Index(iCount)
Also when you want code to be shown on this forum use [ then VB then ] and close vb code with [ then / then VB then ] (take out the thens of course and no spaces.
It just makes reading code easier 
|
__________________
"The more I practice, the luckier I get." - Gary Player
Last edited by Dremandred; 11-05-2003 at 02:27 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|