[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

If Statement Access Query

Posted on 2014-01-15
4
Medium Priority
?
423 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

649 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