N Network Telephone Feb 19, 2007 #1 I am trying to create a public function that returns a recordset in Access 2003. Is this possible?
W WC Justice Feb 19, 2007 #2 In order to provide more information, I add the following: I may use the following in a number of modules: strSQL = "SELECT * FROM tblContracts WHERE ContractNumber = " & dblContractNumber set rs = currentdb.OpenRecordset(strSQL) I would like to move that to a public function to be called, i.e. set rsContractData =ContractData(dblContractNumber) This is a simplistic example, but I just need to know if it is possible. Thanks
In order to provide more information, I add the following: I may use the following in a number of modules: strSQL = "SELECT * FROM tblContracts WHERE ContractNumber = " & dblContractNumber set rs = currentdb.OpenRecordset(strSQL) I would like to move that to a public function to be called, i.e. set rsContractData =ContractData(dblContractNumber) This is a simplistic example, but I just need to know if it is possible. Thanks
D Douglas J. Steele Feb 19, 2007 #3 I can't guarantee it'll work (since I'm too lazy to test <g>), but try: Function ContractData(ContractNumber As Double) As DAO.Recordset Dim strSQL As String strSQL = "SELECT * FROM tblContracts " & _ "WHERE ContractNumber = " & ContractNumber Set ContractData = CurrentDb.OpenRecordset(strSQL) Exit Function
I can't guarantee it'll work (since I'm too lazy to test <g>), but try: Function ContractData(ContractNumber As Double) As DAO.Recordset Dim strSQL As String strSQL = "SELECT * FROM tblContracts " & _ "WHERE ContractNumber = " & ContractNumber Set ContractData = CurrentDb.OpenRecordset(strSQL) Exit Function
W WC Justice Feb 19, 2007 #4 That was it (putting the "as recordset" as part of the function). Thanks!