Link to home
Start Free TrialLog in
Avatar of peispud
peispudFlag for Canada

asked on

Access function returning a recordset

Hi
Using Microsoft Access 2010.  The code below failed on the line as indicated with the message "Invalid use of property"..... "rs" is the target of the error message.


How do I properly call the function below?

Thanks

private sub test()
      Dim rs As DAO.Recordset
      rs = GetRecordSet(Me.[Stock #])       '-------------  Fails here.  
end sub



Public Function GetRecordSet(ByRef TheKey As Long) As DAO.Recordset
Dim strTable As String: Dim StrSQL_Select_Str As String
Dim str1 As String: Dim Str2 As String

strTable = "[Table -- List of Stock Items]"
str1 = "SELECT * FROM " & strTable
Str2 = " Where [Stock #] = " & [Stock #]
StrSQL_Select_Str = str1 & Str2
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(StrSQL_Select_Str, dbOpenDynaset)  ' Get record in [Table -- Retail  / Consigners SKU and Prices]
GetRecordSet = rs
End Function
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peispud

ASKER

I am using the recordset to get a record from another table.  If it's there,  then I will be updating a field or two in that table.
Avatar of peispud

ASKER

Thank you