|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub ADO_有字段名()
Dim myb As Object: Dim s As Integer: Dim mycnt As Integer: Dim x As Integer
[a9:K65536] = Empty
Set mycn = CreateObject("adodb.connection")
Set myrs = CreateObject("adodb.recordset")
mycn.Open "dsn=excel files;hdr=yes;dbq=" & ThisWorkbook.FullName
If Len(Cells(2, 8)) = 0 And Cells(3, 12) <> "" Then '''查询条件只有日期
Sql = "select * from[学生入住登记表$] WHERE (入住时间>=#" & Cells(2, 12) & "# AND 入住时间<=#" & Cells(3, 12) & "#) "
ElseIf Len(Cells(2, 8)) And Cells(3, 12) = "" Then '''查询条件只有宿舍房号
Sql = "select * from[学生入住登记表$] WHERE 宿舍房号='" & Cells(2, 8) & "' "
ElseIf Len(Cells(2, 8)) And Cells(3, 12) <> "" Then '''查询条件为日期与宿舍房号双条件
Sql = "select * from[学生入住登记表$] WHERE (入住时间>=#" & Cells(2, 12) & "# AND 入住时间<=#" & Cells(3, 12) & "#) AND 宿舍房号='" & Cells(2, 8) & "' "
Else '''///什么查询条件也没有
Sql = "select * from[学生入住登记表$] "
End If
myrs.Open Sql, mycn, 1, 1
Range("a9").CopyFromRecordset myrs
End Sub |
评分
-
1
查看全部评分
-
|