【发布时间】:2014-04-09 14:14:11
【问题描述】:
我对 VBA 非常陌生,因此我试图了解与 C# 的差异。 我目前有一个 Sub 来执行批量导入,该导入仅适用于从数据表子表单中选择的单行/记录。
Private Sub cmdImport_Click()
Dim strBatchID As String
On Error GoTo NoBatch
Me.subClaimsToProcessLookup.Form.Controls.Item("txtBatchID").SetFocus
strBatchID = Me.subClaimsToProcessLookup.Form.Controls.Item("txtBatchID").Text
GoTo ContinueImport
NoBatch:
MsgBox "Please select a row", vbOKOnly + vbQuestion, Me.Caption
Exit Sub
ContinueImport:
If Not IsNumeric(strBatchID) Then
MsgBox "Please select a row", vbOKOnly + vbQuestion, Me.Caption
Exit Sub
End If
Dim lngUserID As Long
'...process continues here...
这将只处理用户选择的任何行...现在用户只想通过单击按钮来处理数据表中的所有行。
我想知道 For Each 是否适用于此,而不是必须使用记录导航 (Move Next 等),我不太熟悉……但 For Each 对我来说是 C# 中的一个简单概念。 如: 私有子 cmdImport_Click()
Dim strBatchID As String
On Error GoTo NoBatch
' Add loop here to go through each item in the datasheet view and process it.
For Each Me.subClaimsToProcessLookup.Form.Controls.Item("txtBatchID").Text in Me.subClaimsToProcessLookup.Form.Controls
Me.subClaimsToProcessLookup.Form.Controls.Item("txtBatchID").SetFocus
strBatchID = Me.subClaimsToProcessLookup.Form.Controls.Item("txtBatchID").Text
GoTo ContinueImport
Next
无批次: MsgBox "请选择一行", vbOKOnly + vbQuestion, Me.Caption '退出子 继续
继续导入: If Not IsNumeric(strBatchID) Then MsgBox "请选择一行", vbOKOnly + vbQuestion, Me.Caption '退出子 继续 结束如果
Dim lngUserID As Long
....process continues here....
另外,如果 For Each 可以正确执行此操作,我是否正确设置了“继续 For”流程?
总之,我正在寻找 1) 确认 Form.Controls 可以用作 For Each 中的集合; 和 2) 我为 For Each 设置了正确的流控制(继续)
【问题讨论】:
标签: sql-server-2008 ms-access vba ms-access-2010