我对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是否适用于此,而不是必须使用记录导航
(移动下一步等),我不太熟悉。。。但对于我来说,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
'退出接头
继续
继续导入:
如果不是IsNumeric(strBatchID),则
MsgBox“请选择一行”,vbOKOnly+vbQuestion,Me。Caption
'退出接头
继续
结束条件
Dim lngUserID As Long
....process continues here....
此外,如果For Each可以正确执行此操作,我是否正确设置了“Continue For”流程?
总之,我正在寻找1)表单确认。控件可以用作for Each中的集合;
以及2)我已为For Each设置了正确的流量控制(Continue For)