我正在运行下面的复杂语句以在“SODist”列中提供一个值,该值随着“SalesOrderNo”字段中的每个连续匹配值而递增。我使用“ID”作为自动编号来模拟“行号”功能,但我需要将其扩展到超过 13 行。是否有更好的方法可以使用 VBA 函数来实现我想要的结果?
IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-1)=[SalesOrderNo],IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-9)=[SalesOrderNo],10,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-8)=[SalesOrderNo],9,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-7)=[SalesOrderNo],8,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-6)=[SalesOrderNo],7,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-5)=[SalesOrderNo],6,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-4)=[SalesOrderNo],5,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-3)=[SalesOrderNo],4,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-2)=[SalesOrderNo],3,IIf(DLookUp("[SalesOrderNo]","[Peachtree-Import-Dist]","[ID]=" & [ID]-1)=[SalesOrderNo],2,1))))))))),1) AS SODist