Solved

If Statement Access Query

Posted on 2014-01-15
4
417 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 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 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

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!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

734 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