Solved

If Statement Access Query

Posted on 2014-01-15
4
409 Views
Last Modified: 2014-01-21
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
Comment
Question by:swimehdi
  • 2
  • 2
4 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
ID: 39784289
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
 

Accepted Solution

by:
swimehdi earned 0 total points
ID: 39786235
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39786269
sorry, it was a  typo error on my part..
0
 

Author Closing Comment

by:swimehdi
ID: 39796423
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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now