By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

Pass pairs of listboxes to a sub

P: 5
I am trying to load list boxes from an Access database. I'm looking at 3 tables and for each table I'm loading a list box that has current information and another list box that has expired information based on a date/time field in each table. I'm trying to write a function that will do this instead of writing a procedure for each listbox. I can't get the function to use variables for the listbox. Here is what I'm doing.

Expand|Select|Wrap|Line Numbers
  1. Private Sub InForm()
  3. With Data1
  4.   .RecordSource = "Table1"
  5.   .Refresh
  6.   lstboxes(Table1CurrentListbox,Table1ExpiredListbox)
  8.   .RecordSource = "Table2"
  9.   .Refresh
  10.   lstboxes(Table2CurrentListbox,Table2ExpiredListbox)
  11.   etc....
  12. End Sub
  14. Private Function lstboxes(LSTBOXVAR1, LSTBOXVAR2 as ListBox)
  15. With data1
  16.   Do While Not .Recordset.EOF
  17.     If .Recordset.Fields("Ends").Value > Now Then
  18.       LSTBOXVAR1.AddItem (Current info into current listbox)
  19.     Else
  20.       LSTBOXVAR2.AddItem (Expired info into expired listbox)
  21.     End If
  22.     .Recordset.MoveNext
  23.   Loop
  24.   etc...
I'm trying to pass the name of the listbox objects to the lstbox object variables (I think that's what they are) so this one function can perform the same thing for multiple listboxes. Whenever I try to pass the listbox names I get the error (expected =). Can anyone help with this? Thanks in advance.
Aug 23 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
A couple of quick thoughts.
  • As for the "= expected", just leave off the parentheses when invoking a Sub. In other words, instead of
    lstboxes(Table1CurrentListbox, Table1ExpiredListbox)
    just use
    lstboxes Table1CurrentListbox, Table1ExpiredListbox
  • What version of VB are you using? This can make a difference to the definition of arguments for your procedures.
  • When discussing this, keep in mind there's a difference between passing the listbox (an object/control) and passing the name of the listbox (that would be a string).
Aug 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.