[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 993
  • Last Modified:

DoCmd.openquery

Hi there.  Is it possible to use DoCmd.openquery as a function.
0
leahgillon
Asked:
leahgillon
1 Solution
 
Kelvin SparksCommented:
You can create a function which uses that.
 
Kelvin
0
 
leahgillonAuthor Commented:
These examples seem to use openquery as a sub, not a function.  I'm thinking that perhaps it can't be used as a function to return a recordset and that I may have to use DAO.  What do you think?  Thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
msacc97Commented:
Hi leahgillon,

DoCmd.OpenQuery method will just open query in say datasheet view. To return recordset use type of:

Function fOpenQuery(QueryName As String) As DAO.Recordset
Set fOpenQuery = CurrentDb.QueryDefs(QueryName).OpenRecordset
End Function

The following will print ID field of the first record of Query1 query in immediate window

Sub sTest()
Debug.Print fOpenQuery("Query1")!ID
End Sub

Hope this helps
0
 
leahgillonAuthor Commented:
We ended up going a different route but this was very helpful in clarifying our thinking.  Thanks!
0
 
msacc97Commented:
You are welcome and thank you for the points! :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now