【Access小品】记录顺序调整示例
时 间:2013-05-06 18:19:19
作 者:煮江品茶 ID:10802 城市:武汉
摘 要:【Access小品】记录顺序调整示例
正 文:
Public Sub MoveRecord(ByVal TableName As String, ByVal KeyName As String, _
ByVal CurrentKey As Long, ByVal orientation As Integer, ByVal FormName As String)
'功能:移动记录位置
'参数:TableName -- 数据表名称
' KeyName -- 主键名称(主键应为自动编号类型)
' Currentkey -- 窗体中主键当前值
' orientation -- 移动方向(0=向前,1=向后)
' FormName -- 窗体名称
Dim rs As New ADODB.Recordset
Dim ssql As String
Dim i As Long
Dim val0(), val1()
ssql = "select * from " & TableName
rs.Open ssql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs.Find (KeyName & "=" & CurrentKey)
ReDim val0(rs.Fields.Count - 1)
ReDim val1(rs.Fields.Count - 1)
For i = 1 To UBound(val0)
val0(i) = rs.Fields(i).Value
Next
If orientation = 0 Then
'前移
rs.MovePrevious
If rs.BOF = False Then
For i = 1 To UBound(val0)
val1(i) = rs.Fields(i).Value
rs.Fields(i).Value = val0(i)
Next
rs.MoveNext
For i = 1 To UBound(val0)
rs.Fields(i).Value = val1(i)
Next
rs.Update
End If
Else
'后移
rs.MoveNext
If rs.EOF = False Then
For i = 1 To UBound(val0)
val1(i) = rs.Fields(i).Value
rs.Fields(i).Value = val0(i)
Next
rs.MovePrevious
For i = 1 To UBound(val0)
rs.Fields(i).Value = val1(i)
Next
rs.Update
End If
End If
Forms(FormName).Refresh
rs.Clone: Set rs = Nothing
End Sub
Public Sub InsetRecord(ByVal TableName As String, ByVal KeyName As String, _
ByVal CurrentKey As Long, ByVal orientation As Integer, ByVal FormName As String)
'功能:插入空白记录
'参数:TableName -- 数据表名称
' KeyName -- 主键名称(主键应为自动编号类型)
' Currentkey -- 窗体中主键当前值
' orientation -- 插入方向(0=向前,1=向后)
' FormName -- 窗体名称
Dim rs As New ADODB.Recordset
Dim ssql As String
Dim id As Long
ssql = "select * from " & TableName
rs.Open ssql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs.AddNew
rs.Update
id = rs.Fields(KeyName).Value
'前插
Do While rs.Fields(KeyName).Value <> CurrentKey
If rs.BOF = True Then Exit Do
Call MoveRecord(TableName, KeyName, id, 0, FormName)
rs.MovePrevious
id = rs.Fields(KeyName).Value
Loop
If orientation = 1 Then
'后插
Call MoveRecord(TableName, KeyName, CurrentKey, 1, FormName)
End If
Forms(FormName).Requery
rs.Clone: Set rs = Nothing
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)
- Access快速开发平台--审批选...(11.01)
- ACCESS两张表先各自排序,然后...(10.31)
- Access对子窗体数据进行批量+...(10.30)
- SqlServer中如何用SQL命...(10.29)
- Access报表中的分组功能用代码...(10.28)
- 用Access计算库存结余的一个方...(10.26)
- 最精简的组合框行来源数据快速输入(...(10.25)