“下一个”按钮可循环回到“访问表单”上的第一个 [英] Next Button that cycles back to first on Access Form
问题描述
我一直在尝试创建一个按钮,该按钮可导航回到您在最后一条记录中的第一条记录。我收到无法转到指定记录错误。这是我为该按钮尝试的两种代码样式:
Private Sub Command161_Click()
错误恢复下一个
如果Me.CurrentRecord = acLast然后
DoCmd.GoToRecord,acFirst
其他
DoCmd.GoToRecord,acNext
如果
结束子
私人子命令161_Click()
和Me.Recordset
如果.AbsolutePosition = .RecordCount-1然后
DoCmd.GoToRecord,acFirst
其他
DoCmd.GoToRecord,acNext
如果
结尾为
End Sub
目标是在不允许用户创建新记录的情况下循环回到第一个记录。我尝试过将此代码的允许添加设置为是和现在,结果相同。任何帮助,将不胜感激。
我建议在表单模块中定义一个私有谓词函数,该函数根据活动表单是否返回布尔值在其记录源中显示最后一条记录。
可能会编写这样的函数:
私有函数LastRecordP()为Boolean
,与Me.RecordsetClone
如果不是.EOF,则
.MoveLast
.MoveFirst
LastRecordP = Me.CurrentRecord = .RecordCount
如果
以
结尾则结束End function
您用于按钮控件的 OnClick
事件处理程序可以更简洁地编写为:
< pre class = lang-vb prettyprint-override>
Private Sub Command161_Click()
If LastRecordP Then
DoCmd.GoToRecord,acFirst
Else
DoCmd .GoToRecord`` acNex t
结束如果
结束子
或者,您可以允许函数接受Form对象作为参数,并使用 Me
关键字评估该函数,例如:
私有函数LastRecordP(Frm As Form)为布尔值
,带有Frm.RecordsetClone
如果不是.EOF然后
.MoveLast
.MoveFirst
LastRecordP = Frm.CurrentRecord = .RecordCount
如果
以
结尾的结束函数
Private Sub Command20_Click()
如果LastRecordP(Me )然后
DoCmd.GoToRecord,acFirst
其他
DoCmd.GoToRecord,acNext
如果
End Sub
I've been trying a couple things to create a button that navigates back to the first record you are at the last record. I get the "can't go to specified record" error. Here are the two styles of code I have tried for this button:
Private Sub Command161_Click()
On Error Resume Next
If Me.CurrentRecord = acLast Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End Sub
Private Sub Command161_Click()
With Me.Recordset
If .AbsolutePosition = .RecordCount - 1 Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End With
End Sub
The goal is to loop back around to the first record without allowing the user to create a new record. I've tried this code with "allow additions" set to both yes and now, with the same result. Any help would be appreciated.
I would suggest defining a private predicate function within your form module which returns a boolean value depending on whether or not the active form is displaying the last record in its Record Source.
Such a function might be written:
Private Function LastRecordP() As Boolean
With Me.RecordsetClone
If Not .EOF Then
.MoveLast
.MoveFirst
LastRecordP = Me.CurrentRecord = .RecordCount
End If
End With
End Function
Your OnClick
event handler for your button control could then be written more succinctly as:
Private Sub Command161_Click()
If LastRecordP Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End Sub
Alternatively, you could allow the function to accept a Form object as an argument and evaluate such function using the Me
keyword, e.g.:
Private Function LastRecordP(Frm As Form) As Boolean
With Frm.RecordsetClone
If Not .EOF Then
.MoveLast
.MoveFirst
LastRecordP = Frm.CurrentRecord = .RecordCount
End If
End With
End Function
Private Sub Command20_Click()
If LastRecordP(Me) Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End Sub
这篇关于“下一个”按钮可循环回到“访问表单”上的第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!