我在Access 2010中使用vba,我只是尝试将DAO记录集传递到子例程中。我这样做,所以我不必重复代码(可能有数百行)。我相信这很简单,但每次尝试它都会冻结程序,我不得不重新启动Access并重新添加我的代码。以下是我尝试过的所有代码:
Sub WriteToForms(rs as RecordSet) ' When I press enter, that is when it freezes
Sub WriteToForms(ByVal rs as RecordSet) ' When I press enter, that is when it freezes
Sub WriteToForms(ByRef rs as RecordSet) 'When I press enter, that is when it freezes
然而,当我这样做时:
Sub WriteToForms (types as string)
有效。我查看了多篇文章,上面的代码就是他们的建议。
答案 0 :(得分:0)
将记录集传递给Access中的子例程时,必须指定它是什么类型的记录集。例如:
Sub WriteToForms(rs as recordset)
实际应该是:
Sub WriteToForms(rs as Dao.RecordSet) 'If you are dealing with a DAO recordset.
OR
Sub WriteToForms(rs as ADODB.RecordSet) 'If you are dealing with a ADO recordset.
如果未指定记录集类型,将导致程序冻结,您需要重新启动Access / Excel。