sql - 试图在 VBA 中解决 Object required 错误

标签 sql ms-access compiler-errors vba

我遇到了这个问题。我有一个使用表单的记录源属性检索表数据的表单。打开表单后,我将其记录源属性设置为模块的公共(public)方法 RetrieveMembers。这是下面的代码。

Private Sub Form_Open(Cancel As Integer)
'set Form's record source property to retrieve a Members table
Me.RecordSource = mod_JoinMember.RetrieveMembers

End Sub

'mod_JoinMember Class
Public Function RetrieveMembers() As String

Dim strSQL As String
Set strSQL = "SELECT tbl_Member.Title, tbl_Member.Gender, tbl_Member.LastName, 
tbl_Member.DateofBirth, tbl_Member.Occupation, tbl_Member.PhoneNoWork, 
tbl_Member.PhoneNoHome, tbl_Member.MobileNo, tbl_Member.Email, 
tbl_Member.Address, tbl_Member.State, tbl_Member.Postcode FROM tbl_Member;"
RetrieveMembers = strSQL

End Function

需要对象 抛出错误。

我无法理解这个编译错误。我认为我的代码没有问题,因为 recordsource 是 String 类型的属性。我模块的函数 Retrievemembers 返回一个字符串值。

为什么它对此不满意?

最佳答案

谢谢你的帮助。

我修好了它。原因是因为 String 一开始并不是真正的对象。所以不需要'Set'关键字——因为你不需要显式声明字符串类型的对象!

现在一切都好!

关于sql - 试图在 VBA 中解决 Object required 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9059437/

相关文章:

mysql - 如何内连接2个表并对第三个表求和

sql - 获取给定时间戳和 TZ 名称的 TZ 缩写

sql - PostgreSQL 将列类型从 DATERANGE 更改为 TSTZRANGE 并迁移数据

c# - 使用参数将数据插入access数据库

Java编译时找不到符号

java - 我的程序似乎写得很完美,但停止运行并允许用户在没有扫描仪的情况下输入?

sql - 从查询中排除 NULL 时收到错误

qt - Qt 中的 ODBC 驱动程序使用

ms-access - 微软 Access : how to add 1 row between 2 rows?

c++ - 为什么 C++ 将赋值 (=) 视为重载运算符?