access中vba编程代码大全,access数据库vba语句

http://www.itjxue.com  2023-01-24 06:06  来源:未知  点击次数: 

如何用vba代码将access数据库连接求代码?

Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点,是 Microsoft Office 的系统程序之一。用vba代码将access数据库连接求代码,代码如下:

Sub FYMXDL()

Dim XQID As Integer

Dim JZID As Integer

Dim FYID As Integer

Dim FBXZ As String '分包性质

Dim DW As String

Dim SARR(1 To 31) As Double

Dim rst As New ADODB.Recordset

mYpath = ThisWorkbook.Path "\jzfydata.accdb"

Set cONn = CreateObject("ADODB.Connection")

cONn.ConnectionString = "Provider=Microsoft.Ace.OleDB.12.0;Data Source=" mYpath

cONn.ConnectionString = cONn.ConnectionString ";Jet OLEDB:Database "

cONn.Open

XQID = Cells(3, 2).Value

JZID = Cells(3, 5).Value

'清空改小区-建筑的费用明细

Sql = "delete ?from fymxb where 小区ID=" XQID " AND 建筑ID = " JZID

cONn.Execute Sql

Const kshh = 7

hh = kshh

Do While Cells(hh, 3).Value 0

FYID = Cells(hh, 3).Value

FBXZ = Cells(hh, 11).Text

For i = 1 To 31

SARR(i) = Round(Cells(hh, 13 + i - 1).Value, 2)

Next i

Sql = Sql "," SARR(i)

Next i

Sql = Sql " )"

cONn.Execute Sql

hh = hh + 1

Loop

End Sub

找人看ACCESS里的VBA代码

这个还是很简单的

Dim sRS As DAO.Recordset

Dim dRs As DAO.Recordset

这些是声明变量程序集

Set sDB = CurrentDb 设置当前的db

Set sRS = sDB.OpenRecordset("Select * from sas ")

通过sql语句得到程序集

Set dRs = sDB.TableDefs("v7").OpenRecordset()

直接通过表v7得到程序集

Do While Not sRS.EOF

循环sas那个表的程序集 知道所有的数据都遍历了

dRs.AddNew

给v7那个表加一条数据

If sSum = 20 Then

dRs.Fields(1) = sSum

sNo = DMax("xno", "v7")

dRs.Fields("xno") = sNo + 1

dRs.Update

sSum = 0

End If

这个比较纠结,就是循环20下之后

把v7表中第一个字段更新成20 后面是找到v7中xno最大的一条, 更新xno字段+1

然后更新v7表 sSum重新归0 估计是20个为一个循环这个意思

access VBA代码

语句本身没有问题,问题出在不是操作查询上。我试过,如果是操作查询,类似的语句是可以执行的。如:docmd.RunSQL

"INSERT

INTO

表2

(

字段a,

字段B

)

SELECT

DISTINCT

表1.字段a,

定额.字段B

FROM

表1

WHERE

(((表1.字段a)="

"

'"

tuhao

"'

"

"))

ORDER

BY

表1.字段B"

建议换方式查询。

Excel调用ACCESS的VBA代码怎么写

提供一种在EXCEL使用代码,连接ACCESS,取得数据的方法,看是不是你要的东西:

Sub?AC()

Dim?cnn?As?New?Connection

Dim?rs?As?New?Recordset

Dim?sql?As?String

Dim?qx?As?String

qx?=?"金牛"

cnn.Open?"Provider=Microsoft.Ace.OleDB.12.0;dataSource="??ThisWorkbook.Path??"\数据库.accdb"

sql?=?"select?*?from?[宏站]?where?区域='"?qx??"'"

?

'('"??qx??"'")括号里这段有点BT,一定要这样写才行。

rs.Open?sql,?cnn

?

[a1].CopyFromRecordset?rs

?

EndSub

access vba 编程 请高手发个编程代码。谢谢。谢谢、

'计算1到100的所有偶数的和

Function sum100() As Integer

Dim i As Integer

Dim iSum As Integer

iSum = 0

For i = 2 To 100 Step 2

iSum = iSum + i

Next i

sum100 = iSum

MsgBox (iSum)

iSum = 0

i = 2

While (i = 100)

iSum = iSum + i

i = i + 2

Wend

MsgBox (iSum)

iSum = 0

i = 2

Do Until (i 100)

iSum = iSum + i

i = i + 2

Loop

MsgBox (iSum)

sum100 = iSum

End Function

'计算出1至200能被3整除的所有数, 并统计个数

Function sum200d3() As Integer

Dim i As Integer

Dim iCount As Integer

Dim sNum As String

iCount = 0

sNum = "1至200能被3整除的所有数:"

For i = 1 To 200

If i Mod 3 = 0 Then

sNum = sNum + Str(i) + ", "

iCount = iCount + 1

End If

Next i

MsgBox (sNum + "个数为:" + Str(iCount))

End Function

'附言: 小鬼, 作业要自己完成啊!

(责任编辑:IT教学网)

更多

推荐新书快递文章