1、模块名称和函数名称不能相同;你试着改一下函数的名称
2、如果将函数改名为gstr2,还要设置中间变量aa,如下可以通过,但不知道是否符合你的需要:
Function gstr2(fld As String)
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim aa
'strSQL = "SELECT DM FROM TABDM WHERE KT='" & fld & "'"
strSQL = " SELECT 店面编号 FROM 物管名称 WHERE 合同编号='" & fld & "'"
With rs
.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
Do While Not .EOF
aa = aa & .Fields(0) & ","
.MoveNext
Loop
.Close
End With
Set rs = Nothing
gstr2 = aa
End Function