Results 1 to 3 of 3
  1. #1
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25

    Report Preview


    Hi,

    I have a table with field EmployeeID. On a form (bound to the table) I have a combo box to lookup EmployeeID (from another table) and a command button to preview a report. I want to filter the report by the ID in the combo box.
    With the code below I keep getting an input box asking for a parameter value popping up when I click the preview button, it shows the ID from the combo box.
    How do I stop the input box and have the parameter passed directly to the DoCmd command line.
    __________________________________________________ ___________
    Private Sub cbEmployeeName_Click()

    strName = Me!cbEmployeeName.Column(0)

    End Sub
    __________________________________________________ ___________
    Private Sub coPreviewWOReport_Click()
    On Error GoTo Err_coPreviewWOReport_Click

    Dim stDocName As String
    stDocName = "WOListing"
    strFilter = "[EmployeeID]=" & strName
    DoCmd.OpenReport stDocName, acPreview, , strFilter

    Exit_coPreviewWOReport_Click:
    Exit Sub

    Err_coPreviewWOReport_Click:
    MsgBox Err.Description
    Resume Exit_coPreviewWOReport_Click

    End Sub

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    if employee Id is supposed to be a Integer Field. but strName is a String.

    I would rather have my code on the AfterUpdate Event of the ComboBox Like this:

    Private Sub cbEmployeeName_AfterUpdate()

    Dim strCriteria As String
    Dim stDocName As String

    stDocName = "WOListing"
    strCriteria="[EmployeeID]=" & Me.cbEmployeeName.Column(0)
    DoCmd.OpenReport stDocName, acPreview, , strCriteria
    End Sub

    Assuming the the column(0) holds the employee code which is a string
    if the employee code is a string then

    Private Sub cbEmployeeName_AfterUpdate()

    Dim strCriteria As String
    Dim stDocName As String

    stDocName = "WOListing"
    strCriteria="[EmployeeID]='" & Me.cbEmployeeName.Column(0) & "'"
    DoCmd.OpenReport stDocName, acPreview, , strCriteria
    End Sub

  3. #3
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25
    Thanks Maximus
    Employee is a string as has letters and numbers. Must have been the missing & and sintax on the setting the strFilter. Works a treat now.
    Regards
    Colin

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can't see sub report in print preview
    By LoggyDoggy in forum Access
    Replies: 1
    Last Post: 04-20-2010, 05:38 PM
  2. Report preview from sub form
    By Hillary in forum Forms
    Replies: 2
    Last Post: 01-31-2010, 07:50 AM
  3. Print Preview different from Print Hardcopy
    By peterc in forum Reports
    Replies: 4
    Last Post: 10-27-2009, 05:35 AM
  4. Replies: 6
    Last Post: 09-26-2009, 07:17 AM
  5. Replies: 1
    Last Post: 04-05-2006, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums