打开access数据库,就自动执行对表格code的number字段从小到大排序,用vba怎么写. 80
打开access数据库,就自动执行对表格code的number字段从小到大排序,用vba怎么写,一定是用vba现实的其他的做法就不需要了,代码就在access里面写,不是...
打开access数据库,就自动执行对表格code的number字段从小到大排序,用vba怎么写,一定是用vba现实的其他的做法就不需要了,代码就在access里面写,不是在vb写,求高手.
展开
展开全部
当然可以,用DAO,可以在VB添加DAO组件。
然后,定义参数
'Database Connection
Dim cn As Workspace
Dim db As Database
Dim Rs As Recordset
Dim YOURPWD$, strSQL$, sContent$
'设置数据库
Set cn = DBEngine.Workspaces(0)
Set db = cn.OpenDatabase(sDbPath, False, False, ";pwd=" & YOURPWD)
'打开数据库
strSQL = "Select * From YourTable"
Set Rs = db.OpenRecordset(strSQL, , dbReadOnly)
'取出一个不为NULL的字符串字段值
sContent = trim$(Rs!Item1)
--------------------------------------------------------------
'使用前提在VB中加入VB组件
Dim xlsApp As Object, xlsBook As Object, xlsSheet As Object
Dim Row&, Col&
On Error GoTo ExcelInport_Err
'创建应用Excel程序
Set xlsApp = CreateObject("Excel.Application")
'Excel WorkBook 的添加
Set xlsBook = xlsApp.Workbooks.Add
’取得活动的Excel Sheet
Set xlsSheet = xlsBook.ActiveSheet
'Excel Sheet的标题
xlsSheet.Name = "Your Sheet Name"
'Excel Sheet 内容的填充
With xlsSheet
Row = 1 '行
Col = 1 '列
.Cells(Row, Col).Value = "Your Fill Content"
End With
‘Excel
xlsApp.Visible = True
Set xlsSheet = Nothing
Set xlsBook = Nothing
Set xlsApp = Nothing
Exit Sub
ExcelInport_Err:
'关闭时没有消息框
xlsApp.DisplayAlerts = False
xlsApp.Quit
Set xlsApp = Nothing
然后,定义参数
'Database Connection
Dim cn As Workspace
Dim db As Database
Dim Rs As Recordset
Dim YOURPWD$, strSQL$, sContent$
'设置数据库
Set cn = DBEngine.Workspaces(0)
Set db = cn.OpenDatabase(sDbPath, False, False, ";pwd=" & YOURPWD)
'打开数据库
strSQL = "Select * From YourTable"
Set Rs = db.OpenRecordset(strSQL, , dbReadOnly)
'取出一个不为NULL的字符串字段值
sContent = trim$(Rs!Item1)
--------------------------------------------------------------
'使用前提在VB中加入VB组件
Dim xlsApp As Object, xlsBook As Object, xlsSheet As Object
Dim Row&, Col&
On Error GoTo ExcelInport_Err
'创建应用Excel程序
Set xlsApp = CreateObject("Excel.Application")
'Excel WorkBook 的添加
Set xlsBook = xlsApp.Workbooks.Add
’取得活动的Excel Sheet
Set xlsSheet = xlsBook.ActiveSheet
'Excel Sheet的标题
xlsSheet.Name = "Your Sheet Name"
'Excel Sheet 内容的填充
With xlsSheet
Row = 1 '行
Col = 1 '列
.Cells(Row, Col).Value = "Your Fill Content"
End With
‘Excel
xlsApp.Visible = True
Set xlsSheet = Nothing
Set xlsBook = Nothing
Set xlsApp = Nothing
Exit Sub
ExcelInport_Err:
'关闭时没有消息框
xlsApp.DisplayAlerts = False
xlsApp.Quit
Set xlsApp = Nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |