Private Sub CommandButton1_Click() Dim CNN As New ADODB.Connection Dim RST As New ADODB.Recordset Dim Stpath, strSQL As String Stpath = ThisWorkbook.Path & Application.PathSeparator & "DATA.mdb" CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath If ComboBox日期.Value = "" Then strSQL = "Select * from 门诊数据库2 WHERE 姓名 LIKE '" & ComboBox姓名.Value & "'" ElseIf ComboBox姓名.Value = "" Then strSQL = "Select * from 门诊数据库2 WHERE 日期 LIKE '" & ComboBox日期.Value & "'" Else strSQL = "Select * from 门诊数据库2 WHERE 姓名 LIKE '" & ComboBox姓名.Value & "%'" & "AND 日期 between #" & ComboBox日期 & "# AND #" & ComboBox截至日期 & "#" End If RST.Open strSQL, CNN Sheet1.Range("A2:I8000").ClearContents Sheet1.Cells(2, 1).CopyFromRecordset RST RST.Close Set RST = Nothing Set CNN = Nothing End Sub
[此贴子已经被作者于2008-1-16 9:11:52编辑过] |