vba - 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.
解决方案
看起来你是从 25 中减去字段的长度,但是如果长度是 30 呢?您需要确定字段的长度。你能发布更多你的代码吗?这将有很大帮助。
推荐阅读
- angular - 如何在 Angular 表单无效时延迟错误消息,但一旦有效就将其删除?
- python - 如何将带有dicts的pandas列中的值移动到仅包含该值的新列中
- java - Android FileObserver onEvent 不起作用
- python - numpy函数内的熊猫数据框分组操作
- google-sheets - 如何在 Google 表格中执行 SUMPRODUCT,但以两个向量中的文本为条件?
- python - 使用 ipyleaflet 保存 GeoJson / 访问标记列表
- excel - 如何复制(从 COL)和粘贴(到 ROW)(替换特定位置的数据)?
- git - 获取“env:bash\r:没有这样的文件或目录”我正在使用 Mac 终端并在执行 git commit 时遇到此问题
- sql - 大查询中的数组
- android - 排球没有提出要求