?
Solved

If Statement Access Query

Posted on 2014-01-15
4
Medium Priority
?
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 750 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

765 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