Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Posts
    39

    Unanswered: Print/Preview report for current record, unwanted parameter box.

    Have a button on a form set to preview a report for the current record on the form. Simple enough I thought !
    When I click the button instead of the report preview a parameter box comes up for the field ( NI ) that Im using to specify for the current record. Weirdly the actual parameter for the current record appears in the title bar of this parameter box, if I then type this parameter in to the box the record is then previewed .

    Ive used the same code ( with the form/report references amended of course) in a different database and it works fine ie no parameter box.

    Ive tried setting up a new report ( a few actually) in this database to preview but get the same parameter box.

    Any advice suggestions please ?

    Code for button is as follows


    Private Sub Print_Training_Record_Click()
    On Error GoTo Err_Print_Training_Record_Click

    Dim stDocName As String

    stDocName = "rptStaffNames"
    strWhere = "NI=" & Me!NI
    DoCmd.OpenReport stDocName, acPreview, , strWhere
    Exit_Print_Training_Record_Click:
    Exit Sub

    Err_Print_Training_Record_Click:
    MsgBox Err.Description
    Resume Exit_Print_Training_Record_Click

    End Sub



    This is driving me nuts have searched this forum and googled galore but still cant get it right.
    Thanks Keith

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    What is the data type of NI in the table?
    Paul

  3. #3
    Join Date
    Jul 2009
    Posts
    39
    It's just text, it is the primary key for the table, indexed and required

  4. #4
    Join Date
    Jul 2009
    Posts
    39
    Indexed Yes ( no duplicates )

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Then try

    strWhere = "NI='" & Me!NI & "'"
    Paul

  6. #6
    Join Date
    Jul 2009
    Posts
    39
    Brilliant Paul , worked perfectly. If you have the time could you please explain what the problem was and why the addition of & "'" sorted it, ie what is the & "'" doing. I'm going to add some other report buttons and will presumably have to add this again so would like to know what I'm doing !
    Many thanks
    Keith
    This forum is brilliant , wish I'd come across it months ago !

  7. #7
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Numeric, text and date values are treated differently. I explain a little about it here:

    Open a second form to the record
    Paul

  8. #8
    Join Date
    Jul 2009
    Posts
    39
    Thanks Paul, your explanation was neat and understandable by a novice , me
    Keith

Posting Permissions

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