• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

If Statement Access Query

Hello Expert,

I am trying to develop an if statement for my form in VBA:  

If Query "XYZ" is open then DoCmd.CloseQuery "XYZ"

Not sure if possible. I appreciate your help.
0
swimehdi
Asked:
swimehdi
  • 2
  • 2
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
you can just call a command to close the query,

if the query is open it will close the query

DoCmd.CloseQuery "XYZ"


if the query is close, nothing will happen..

or you can use this

if SysCmd(acSysCmdGetObjectState, acQuery,  "XYZ") <> 0 then

DoCmd.CloseQuery "XYZ"

end if
0
 
swimehdiAuthor Commented:
The if statement generated a compile error:  Method or data member not found.

I resorted to your first suggestion.  

"you can just call a command to close the query,
if the query is open it will close the query

DoCmd.CloseQuery "XYZ"

if the query is close, nothing will happen.."


It worked only if I type it exactly as follows:

DoCmd.Close acQuery, "XYZ"

Thank you for your help.
0
 
Rey Obrero (Capricorn1)Commented:
sorry, it was a  typo error on my part..
0
 
swimehdiAuthor Commented:
The VBA wording that worked for me is:

DoCmd.Close acQuery, "XYZ"
 
and NOT

 DoCmd.CloseQuery "XYZ"

Expert's suggestion helped.
0

Featured Post

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.

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