Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: List Box

  1. #1
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Red face Unanswered: List Box

    I have list box that pull all the reports. In the past i have use following code for it to list all report but the code doesn't display the reports that start with example "rptSample"

    Now what i wann do is that i wann to see all report in list box and most of reports start with "rptSample". And i do not want to display "rptSample" in list box rather i want just "Sample" in list box

    Set objCP = Application.CurrentProject

    For Each objAO In objCP.AllReports
    If Mid(objAO.Name, 1, 3) <> "rpt" Then
    strValues = strValues & objAO.Name & ";"
    End If
    Next objAO
    Skharva

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Re: List Box

    Code:
    Set objCP = Application.CurrentProject
    
    For Each objAO In objCP.AllReports
        If Left$(objAO.Name, 3) = "rpt" Then
        strValues = strValues & Right$(objAO.Name, LEN(objAO.name) - 3) & ";"
    Else
        strValues = strValues &  objAO.Name & ";"
    End If
    Next objAO
    Last edited by Teddy; 03-19-04 at 11:39.

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    two irrelevant observations:
    mid$() will be faster than mid()
    left$() will be faster than mid$()

    for the rest, i'm not sure where the question is.

    izy


    later: Teddy found the question, and answered it
    currently using SS 2008R2

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ditto: replace right() with right$() izy
    currently using SS 2008R2

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by izyrider
    ditto: replace right() with right$() izy
    Fixed, good catch.

  6. #6
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    Originally posted by izyrider
    ditto: replace right() with right$() izy
    For Each objAO In objCP.AllReports
    If Mid$(objAO.Name, 1, 3) <> "rpt" Then
    strValues = strValues & Right$(objAO.Name, Len(objAO.Name) - 3) & ";"
    End If
    Next objAO

    this code still doesn't work. I'm still trying to figure out this. If anyone does figure it out please post it

    Thanks
    Skharva

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by Skharva
    For Each objAO In objCP.AllReports
    If Mid$(objAO.Name, 1, 3) <> "rpt" Then
    strValues = strValues & Right$(objAO.Name, Len(objAO.Name) - 3) & ";"
    End If
    Next objAO

    this code still doesn't work. I'm still trying to figure out this. If anyone does figure it out please post it

    Thanks
    Try my updated code, I didn't properly read the question the first time and editted it a minute later...

    You're too fast for me!!!

  8. #8
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Thumbs up

    Originally posted by Skharva
    For Each objAO In objCP.AllReports
    If Mid$(objAO.Name, 1, 3) <> "rpt" Then
    strValues = strValues & Right$(objAO.Name, Len(objAO.Name) - 3) & ";"
    End If
    Next objAO

    this code still doesn't work. I'm still trying to figure out this. If anyone does figure it out please post it

    Thanks

    Got it to work

    Thanks for all your help
    Skharva

  9. #9
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    Originally posted by Skharva
    Got it to work

    Thanks for all your help
    One more questions i don't know if this is possible

    I'm trying to center all reports name in listbox

    Also, when i have reoprt name "StudyNo" can i do view it as "Study No" in list box ?
    Skharva

  10. #10
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Red face

    Originally posted by Skharva
    One more questions i don't know if this is possible

    I'm trying to center all reports name in listbox

    Also, when i have reoprt name "StudyNo" can i do view it as "Study No" in list box ?
    Using the following code i'm able to get rid of "rpt" when reports are display in Listbox

    Set objCP = Application.CurrentProject

    For Each objAO In objCP.AllReports
    If Left$(objAO.Name, 3) = "rpt" Then
    strValues = strValues & Right$(objAO.Name, Len(objAO.Name) - 3) & ";"
    End If
    Next objAO


    But when i try to preview reports i get error massage saying that Access can't find the reports "rptSample"
    Skharva

  11. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you can do
    StudyNo -> Study No

    but any simple algorithm to do this will also do
    HP LaserJet -> H P Laser Jet

    you could complicate the algorithm but you can't handle all cases

    and it will be SLOW! you will need to step through every character of every string to see if it is uppercase.

    have you considered stuffing your report names into a table that includes the "real" report name and a "user-friendly" report name? it will be faster, easier, and without unfortunate errors.

    izy

    later: like Teddy said - you are too fast. i'm still replying to your previous question, but i think the table approach will solve BOTH.
    currently using SS 2008R2

  12. #12
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    Originally posted by izyrider
    you can do
    StudyNo -> Study No

    but any simple algorithm to do this will also do
    HP LaserJet -> H P Laser Jet

    you could complicate the algorithm but you can't handle all cases

    and it will be SLOW! you will need to step through every character of every string to see if it is uppercase.

    have you considered stuffing your report names into a table that includes the "real" report name and a "user-friendly" report name? it will be faster, easier, and without unfortunate errors.

    izy

    later: like Teddy said - you are too fast. i'm still replying to your previous question, but i think the table approach will solve BOTH.
    No i haven't considered stuffing reports names into table. You have any example of that i can see ?
    Skharva

  13. #13
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    no i haven't, but i can imagine:

    tblReports ([realName] PK, [friendlyName])
    "rptStudyNo", "Study Number Report"
    "rptXX1027", "Overdue Samples Report"
    etc.

    then a list called lstReports using tblReports as source (with [realName] hidden if you like)

    then a GO button with:

    private sub GO_Click
    docmd.openreport lstReports.realName
    end sub


    ??? izy
    currently using SS 2008R2

  14. #14
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by Skharva
    No i haven't considered stuffing reports names into table. You have any example of that i can see ?
    Sweet bald-headed lizzy am I slow today!!

    I use this method HEAVILY in the reports application that I support. Basically I have a bunch of reports that are selected via an interface consisting of a form with two listboxes and a text box that holds descriptions of a report.

    This is done using two tables:

    Reports -

    report_id: int (PK)
    report_type_id: int (FK)
    name: string
    long_name: string 'this is the name to be displayed
    description: string

    ReportTypes

    report_type_id (PK)
    description: string

    In the AfterUpdate event for the first listbox, I filter my record set according to type_id and populate a second listbox according the new recordset. In the second listbox, I filter according to report_id. You could alter this approach to add as many filters as you would like, each by key.

    I can't post the code that I use because it's a work for hire, but if you'd like I would be happy to walk you through designing something comparable of your own. It's really a piece of cake.

  15. #15
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...and once you use a table, you no longer have to worry about the algo time. you could run the algo at startup, or even give the user a button "Check for new reports"

    here is a "StudyNo" to "Study No" algo example

    Code:
    private function unCondense (strCondensed as string) as string
    dim aPointer as integer
    dim amContinuing as boolean
    dim outString as string
    
    
    amContinuing = false 
    
    for aPointer = 1 to len(strCondensed)
      if amContinuing then
        if asc(mid$(strCondensed, aPointer, 1) = asc(" ") then
          outString = outString & mid$(strCondensed, aPointer, 1)
          amContinuing = false
        else
          if asc(mid$(strCondensed, aPointer, 1) < asc("A") then
            outString = outString & mid$(strCondensed, aPointer, 1)
          else
            if asc(mid$(strCondensed, aPointer, 1) > asc("Z") then
              outString = outString & mid$(strCondensed, aPointer, 1)
            else
              outString = outString & " " & mid$(strCondensed, aPointer, 1)
            endif
          endif
          amContinuing = true
        endif        
      else
        outString = outString & mid$(strCondensed, aPointer, 1)
        amContinuing = true
      endif
    next
    unCondense = outString
    end function
    this does not handle "HP", but you could add:
    dim lastWasUC as boolean
    which you set true (if it was!) and replace

    if amContinuing then

    with

    if amContinuing or lastWasUC then

    this does not handle "LaserJet"
    and so on, and so on, and so on!

    izy

    LATER: which i have not checked, but you get the idea i guess
    Last edited by izyrider; 03-19-04 at 13:11.
    currently using SS 2008R2

Posting Permissions

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