Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Truro, Cornwall, UK

    Unanswered: Listbox and Win98se

    Hi all,
    Using the script below to print reports works as needed on Win ME and Acess 97 but will not fill the listbox when used with Win 98se. It,s probably something simple that I have missed but cannot see it for looking.
    The script was written by Allen Browne and does whats need except on win98.
    Any help and advice most greatfull.
    Thanks Kevin.

    Code enclosed,

    Callback Function

    If you don't like the undocumented approach, or would like to experiment
    with call back functions, here is the other alternative.

    1. Create a form with:
    * a *list box* named /lstReports/, with a label /Reports/;
    * a *check box* named /chkPreview/, with a label /Preview/;
    * a *command button* named /cmdOpenReport/, with caption /Open

    2. Set the command button's *OnClick* property to /[Event
    Procedure]/. Click the "*...*" button beside this property to open
    the code window, and enter the following:

    Private Sub cmdOpenReport_Click()
    ' Purpose: opens the report selected in the list box.
    On Error GoTo cmdOpenReport_ClickErr
    If Not IsNull(Me.lstReports) Then
    DoCmd.OpenReport Me.lstReports, IIf(Me.chkPreview.Value, acViewPreview, acViewNormal)
    End If
    Exit Sub

    Select Case Err.Number
    Case 2501 ' Cancelled by user, or by NoData event.
    MsgBox "Report cancelled, or no matching data.", vbInformation, "Information"
    Case Else
    MsgBox "Error " & Err & ": " & Error$, vbInformation, "cmdOpenReport_Click()"
    End Select
    Resume Next
    End Sub

    3. Set the list box's *RowSourceType* property to /EnumReports/.
    Leave the *RowSource* property blank.

    4. Create a new *module* and copy the function below into this module:

    Function EnumReports(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
    ' Purpose: Supplies the name of all saved reports to a list box.
    ' Usage: Set the list box's RowSourceType property to: EnumReports
    ' leaving its RowSource property blank.
    ' Notes: All arguments are provided to the function automatically.
    ' Author: Allen Browne Feb.'97.

    Dim db As Database, dox As Documents, i As Integer
    Static sRptName(255) As String ' Array to store report names.
    Static iRptCount As Integer ' Number of saved reports.

    ' Respond to the supplied value of "code".
    Select Case code
    Case acLBInitialize ' Called once when form opens.
    Set db = CurrentDb()
    Set dox = db.Containers!Reports.Documents
    iRptCount = dox.Count ' Remember number of reports.
    For i = 0 To iRptCount - 1
    sRptName(i) = dox(i).Name ' Load report names into array.
    EnumReports = True
    Case acLBOpen
    EnumReports = Timer ' Return a unique identifier.
    Case acLBGetRowCount ' Number of rows
    EnumReports = iRptCount
    Case acLBGetColumnCount ' 1 column
    EnumReports = 1
    Case acLBGetColumnWidth ' 2 inches
    EnumReports = 2 * 1440
    Case acLBGetValue ' The report name from the array.
    EnumReports = sRptName(row)
    Case acLBEnd
    Erase sRptName ' Deallocate array.
    iRptCount = 0
    End Select
    End Function


    How the callback function works

    The RowSourceType property of a list box can be used to fill the box
    programatically. The five arguments for the function are provided
    automatically: Access calls the function repeatedly using these
    arguments to indicate what information it is expecting.

    During the initalization stage, this function uses DAO (Data Access
    Objects) to retrieve and store the names of all reports into an static
    array. (Note: it is necessary to use the /Containers!Reports.Documents/
    collection, as the /Reports/ object refers only open reports.)

    The command button simply executes an OpenReport action. If the check
    box is checked, the report is opened in Preview mode, else it is printed

  2. #2
    Join Date
    Aug 2004
    Kevin, I can't see any reason why this doesn't work in 98. BUT!!!! there was a listbox problem with access97. So.... does the win98 box have sp2b installed?

    I think that is the problem..


  3. #3
    Join Date
    Dec 2002
    Truro, Cornwall, UK
    Howard thanks for the quick reply.
    Win98 box has sp2b installed I'm sorry to say. I'll keep pluging away at it.

    Thanks Kevin.

  4. #4
    Join Date
    Aug 2004
    If I think of anything else I'll let you know.

    Cheers for now

Posting Permissions

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