The code to open the filtered form in report view is not woking

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abdul050
    New Member
    • Dec 2015
    • 8

    The code to open the filtered form in report view is not woking

    Hi Guys,

    I am trying to open the filtered form in report view but I don't understand why it's not working. Could you please tell me where is the problem in my code ?

    I just want to open the form in print preview and if I filtered something in that form then I want to open that filtered form in print preview also.

    Here is my code.

    Code:
     
    Private Sub Command25_Click()
        Dim strSearch As String
        Dim strText As String
         'strText = Me.TxtBox.Value
        If IsNull(Me.TxtBox.Value) Or Me.TxtBox = "" Then
        MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
        Me.TxtBox.BackColor = vbYellow
        Me.TxtBox.SetFocus
    Else
        strText = Me.TxtBox.Value
        strSearch = "SELECT * from Qery_PVT_Demand_Forecast where ((Support_Status like ""*" & strText & "*"") or (BUOrgKey like ""*" & strText & "*""))"
        Me.RecordSource = strSearch
        Me.TxtBox.BackColor = vbWhite
    End If
    End Sub
    
    ' Command to open the filtered Report in Print Preview
    Private Sub cmdOpenReport_Click()
        DoCmd.OpenReport "[Rpt_PVT_Demand_Forecast]", acViewPreview, , Me.Filter
        End If
    End Sub
  • mbizup
    New Member
    • Jun 2015
    • 80

    #2
    Is your filter form' recordsource bound to "Qery_PVT_Deman d_Forecast"? And is that spelled correctly? (it looks like you are missing a 'u' in "Qery').

    Instead of setting the recordsource of the form try setting the filter property (since that is later read by your Open Report code). To set the filter, you just need the criteria (ie: the WHERE clause without the WHERE keyword).



    Code:
        strSearch = "((Support_Status like ""*" & strText & "*"") or (BUOrgKey like ""*" & strText & "*""))"
        Me.Filter = strSearch
        Me.FilterOn = True

    Comment

    • abdul050
      New Member
      • Dec 2015
      • 8

      #3
      yes it's spelled correctly. My Supervisor gave the name like this "Qery".

      Thank you so much for your help. It's working now.

      Comment

      Working...