首页 > 解决方案 > Error 5 vba, invalid call when looping through a recordset

问题描述

Trying to create a string to paste to the body of an email. Getting an Error 5 invalid call when looping through a record set. It goes through the first record fine, but once it gets to the second record, it throws the error.

Do While Not recSet.EOF
   For intCtr = 0 To recSet.Fields.Count - 1
      strData = strData & recSet.Fields(intCtr) & Space(25 - Len(Nz(recSet.Fields(intCtr))))
Next
   strData = Trim(strData) & vbCrLf
   recSet.MoveNext
   Debug.Print strData
Loop

It's supposed to paste the results from a query into the body of the email.

标签: vbams-access

解决方案


看起来你是从 25 中减去字段的长度,但是如果长度是 30 呢?您需要确定字段的长度。你能发布更多你的代码吗?这将有很大帮助。


推荐阅读