|
- Private Sub CommandButton1_Click()
- Dim strSql$
- Dim strFind$
- Dim strCondition1$
- Dim strCondition2$
- Dim Database As String
- On Error GoTo Errcheck
-
- '检测查询的项目
- Select Case True
- Case Me.OptionButton1.Value
- strFind = OptionButton1.Caption
- Case Me.OptionButton2.Value
- strFind = OptionButton2.Caption
- Case Me.OptionButton3.Value
- strFind = OptionButton3.Caption
- Case Me.OptionButton4.Value
- strFind = OptionButton4.Caption
- Case Else
- MsgBox "请选择要查找的内容"
- Exit Sub
- End Select
- Database = "data"
- strSql = "select 报销月份,序号,定点医疗机构名称,医保卡号,单位名称,姓名,性别," & _
- "年龄,入院日期,出院日期,住院天数,出院诊断,本次住院医疗费总额,甲类药费," & _
- "乙类药费,进口药费,自费药费,超出范围,进口材料费,国产材料费," & _
- "特殊检查费特殊治疗费,丙类项目,其它费用,起付段金额,个人政策自付小计," & _
- "自费药品及自费项目,实际结算自付,统筹基金支付,大病求助基金支付," & _
- "个人支付金额,本年住院次数,本年范围内费用累计,本年大病范围内费用累计 from " & Database
- '检测查询的内容
- Select Case True
- Case Len(Me.TextBox1.Text) > 0
- strCondition1 = " where " & strFind & "='" & Me.TextBox1.Text & "' "
- Case Else
- strCondition1 = " where " & strFind & " like '%' "
- End Select
- '时间条件
- Select Case True
- Case Len(Me.TextBox2.Text) = 0 And Len(Me.TextBox3.Text) = 0
- Case Len(Me.TextBox2.Text) = 0
- strCondition2 = " and 录入时间<=#" & Me.TextBox3.Text & "#"
- Case Len(Me.TextBox3.Text) = 0
- strCondition2 = " and 录入时间>=#" & Me.TextBox2.Text & "#"
- Case Else
- strCondition2 = " and 录入时间 between #" & Me.TextBox2.Text & "# and #" & Me.TextBox3.Text & "#"
- End Select
- 'MsgBox strSql & strCondition1 & strCondition2
- '调用查询过程
- Call ADOQuery(strSql & strCondition1 & strCondition2)
- If Me.CheckBox1 Then
- Dim lLastRow&
- lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
- If lLastRow > 5 Then
- Cells(lLastRow + 1, "l").Value = "合计"
- Cells(lLastRow + 1, "m").Formula = "=sum(m6:m" & lLastRow & ")"
- Cells(lLastRow + 1, "m").AutoFill Cells(lLastRow + 1, "m").Resize(, 21), xlFillDefault
- End If
- End If
- Exit Sub
-
- Errcheck:
- MsgBox Err.Number & vbNewLine & _
- Err.Description
- End Sub
复制代码 |
|