|
楼主 |
发表于 2013-6-12 20:57
|
显示全部楼层
本帖最后由 qinhuan66 于 2013-6-12 21:05 编辑
hwc2ycy 发表于 2013-6-12 20:33
把*换成要取的字段名
sql="select 姓名,身份证号,报考职位 from GKZP where 操作员='小邓'"
老师按照你的要求如果在后面加上排序好像原有数据会乱,如下图:谢谢
Private Sub CommandButton1_Click()
Dim cnn As Object, SQL$
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\GKZP.mdb;Jet OLEDB:Database Password=695360052"
'SQL = "select * from GKZP where 操作员='小邓' and 操作员='小邓'" '*号提取全部
SQL = "select 姓名,身份证号,报考职位 from GKZP where 操作员='小邓'" '取姓名、身份证号、报考职位
Range("a1").CurrentRegion.Offset(5).ClearContents
Range("a3").CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
'以下为按报考职位排序(升序)
Range("A3:C1000").Sort Key1:=Range("C3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
End Sub
没有执行命令前的图
执行命令后的图片如下图
|
|