|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 查询()
Dim CN, sql$, myfile$, rs
myfile = ThisWorkbook.Path & "\数据库.mdb"
Set CN = CreateObject("ADODB.Connection")
Set rs = CreateObject("adodb.Recordset")
CN.Open "provider=microsoft.jet.oledb.4.0;data source=" & myfile
sql = "select 工号,姓名,部门,岗位,基本工资,卡号,备注,单价,备注,入职日期,离职日期 from 员工信息 " _
& "where 工号='" & [a2] & "' or 姓名='" & [b2] & "'or 部门='" & [c2] & "'or 岗位='" & [d2] & "'or 基本工资='" & [e2] & "'or 卡号='" & [f2] & "'or 备注='" & [g2] & "' "
rs.Open sql, CN, 1, 1
If rs.RecordCount = 0 Then
rs.Close: CN.Close
Set rs = Nothing: Set CN = Nothing
MsgBox "无此数据"
Else
[a2:K2] = ""
[a2].CopyFromRecordset rs
rs.Close: CN.Close
Set rs = Nothing: Set CN = Nothing
End If
End Sub
注:工号,基本工资,单价为数值型,其他为文本类型。
|
|