Private Sub btn_print_Click()
   Dim rpt_pot As Integer
   Dim rpt_cp As String
   Dim query_sql As String
   Dim cn_rpt_cnstr As String
   dt_Start = Trim(CStr(DTP_start.value))
   dt_end = Trim(CStr(DTP_end.value))
   query_sql = " where yy_date between  Convert(VarChar(10),'" + dt_Start + " ', 120)  and  Convert(VarChar(10), '" + dt_end + "', 120)"
   If Trim(cb_depart.Text) <> "全部" Then
      query_sql = query_sql + " and depart =  '" + Trim(cb_depart.Text) + "'"
      rpt_pot = 1
      rpt_cp = Trim(cb_depart.Text)
      If Trim(Cb_area.Text) <> "全部" Then
         query_sql = query_sql + " and depart =  '" + Trim(cb_depart.Text) + "'"
         query_sql = query_sql + " and name = '" + Trim(Cb_area.Text) + "'"
         rpt_pot = 2
         rpt_cp = Trim(cb_depart.Text) + Trim(Cb_area.Text) + "地区"
      End If
   Else
      rpt_pot = 0
      If Trim(Cb_area.Text) <> "全部" Then
         query_sql = query_sql + " and name = '" + Trim(Cb_area.Text) + "'"
         rpt_pot = 3
         rpt_cp = Trim(Cb_area.Text)
      End If
      
   End If
   cn_rpt_cnstr = "Provider=MSDataShape.1;Persist Security Info=True;Data Source="
   cn_rpt_cnstr = cn_rpt_cnstr & serv & ";User ID=sa;Password=" + psd + ";Initial Catalog=zyzy;Data Provider=SQLOLEDB.1"
   det_rpt.cn_rpt.CursorLocation = adUseClient
   det_rpt.cn_rpt.CommandTimeout = 10
   det_rpt.cn_rpt.connectionstring = cn_rpt_cnstr
   det_rpt.cn_rpt.Open
   det_rpt.Commands.Item("rpt_fhtj_Grouping").commandtext = "SHAPE {SELECT * FROM v_sell_fhtj " + query_sql + "}  AS rpt_fhtj COMPUTE rpt_fhtj  BY 'depart','name','guige'"
   det_rpt.rsrpt_fhtj_Grouping.Source = "SHAPE {SELECT * FROM v_sell_fhtj " + query_sql + "}  AS rpt_fhtj COMPUTE rpt_fhtj  BY 'depart','name','guige'"
   det_rpt.rsrpt_fhtj_Grouping.ActiveConnection = det_rpt.cn_rpt
   det_rpt.rsrpt_fhtj_Grouping.Open
   det_rpt.Commands.Item("rpt_fhtj_Grouping").ActiveConnection = det_rpt.cn_rpt
   det_rpt.Commands.Item("rpt_fhtj_Grouping").Execute
   If det_rpt.rsrpt_fhtj_Grouping.RecordCount > 0 Then
        Select Case rpt_pot
             Case 0
                  rpt_cp = "各部门、地区发货情况表"
                  drt_fhtj_00.Sections("s_title").Controls("lb_title").Caption = rpt_cp
                  drt_fhtj_00.Sections("s_title").Controls("lb_date").Caption = "时间:" + ndate                  drt_fhtj_00.Show 1
                   
             Case 1
                  rpt_cp = rpt_cp + "各地区发货情况表"
                  drt_fhtj_01.Sections("s_title").Controls("lb_title").Caption = rpt_cp
                  drt_fhtj_01.Sections("s_title").Controls("lb_date").Caption = "时间:" + ndate
                  drt_fhtj_01.Show 1
             Case 2
                  rpt_cp = rpt_cp + "发货情况表"
                  drt_fhtj_02.Sections("s_title").Controls("lb_title").Caption = rpt_cp
                  drt_fhtj_02.Sections("s_title").Controls("lb_date").Caption = "时间:" + ndate
                  drt_fhtj_02.Show 1
            Case 3
                  rpt_cp = rpt_cp + "地区各部门发货情况表"
                  drt_fhtj_03.Sections("s_title").Controls("lb_title").Caption = rpt_cp
                  drt_fhtj_03.Sections("s_title").Controls("lb_date").Caption = "时间:" + ndate
                  drt_fhtj_03.Show 1
        End Select
   Else
       MsgBox "记录为零,不能生成报表!", vbOKOnly, "提示信息"
   End If
   On Error GoTo lable_0
     det_rpt.rsrpt_fhtj_Grouping.Close
     det_rpt.cn_rpt.Close
lable_0:
    Err.Clear
End Sub