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

Partial Display of List Items

P: 10
I have a list box control on an Access 2007 Form called "lstReports". I would like to populate this list box with report names like: rptMaintParts, rptMaintWorkorders, rptMaintParts On Order, etc. However, I do not want the "rptMaint" part of the report name to display in the text box. I once had the code to provide this functionality, but that was many years ago.

I would appreciate it greatly if someone would lead me in the right direction.

Thanks in advance,

Tempo
Jun 10 '11 #1
Share this Question
Share on Google+
5 Replies


100+
P: 759
In the Property Sheet, under Data tab, set the Row Source Type for your list to Value List. Then use a code like this:

Expand|Select|Wrap|Line Numbers
  1. Dim Rpt As String
  2.     Rpt = Mid("rptMaintParts", 9)
  3.         lst.AddItem (Rpt)
  4.     Rpt = Mid("rptMaintWorkorders", 9)
  5.         lst.AddItem (Rpt)
  6.     Rpt = Mid("rptMaintParts On Order", 9)
  7.         lst.AddItem (Rpt)

Maybe is better to create a function to return the string you need:

Expand|Select|Wrap|Line Numbers
  1. Private function ReturnRaportName(Rpt As String) As String
  2.     ReturnRaportName = = Mid(Rpt, 9)
  3. End Function
Then apply this function:
Expand|Select|Wrap|Line Numbers
  1.     lst.AddItem (ReturnRaportName("rptMaintParts"))
Good luck !
Jun 10 '11 #2

NeoPa
Expert Mod 15k+
P: 31,560
So, you want your ListBox to reflect the names of all reports that start rptMaint, but only to show those parts of the name after rptMaint.

Your code would need to go through all the reports checking for the match then adding the text after the match to the list :

Expand|Select|Wrap|Line Numbers
  1. Dim strList As String
  2. Dim rpt As Report
  3.  
  4. For Each rpt In CurrentProject.AllReports
  5.     If Left(rpt.Name, 8) = "rptMaint" Then _
  6.         strList = strList & "," & Mid(rpt.Name, 9)
  7. End With
  8. Forms!frmBlahBlah.lstReports.RowSource = Mid(strList, 2)
Clearly, Row Source Type for lstReports must already be set to "Value List".
Jun 13 '11 #3

P: 10
Hi Guys!

This is to say a "Big Thank You" to both Mihail and NeoPa for each of your responses to my question. The code snippets are definitely a step in the right direction.

Not sure what I need to do to close this thread, but it's a done deal.


Thanks again, Tempo
Jun 17 '11 #4

NeoPa
Expert Mod 15k+
P: 31,560
You're welcome.

See Marking a Post as 'Best Answer'.
Jun 17 '11 #5

100+
P: 759
Glad to help you.
Good luck !
Jun 18 '11 #6

Post your reply

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