By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

String variable in DoCmd.Close

P: 24
Good morning everybody,
I'm trying to use a string variable inside the DoCmd.Close statement. Despite many attempts this doesn't work. Does anybody have a solution for that?

I have a form called frmFunctMod1 (there will be more forms like this, this is why I need to use the name as variable). Here is my (non-working) code trying to close the form:

Expand|Select|Wrap|Line Numbers
  1.  
  2. strModuleNameFull = "frmFunctMod1"
  3. Debug.Print "check string name", strModuleNameFull
  4. DoCmd.Close acForm, " ' &  strModuleNameFull & ' ", acSaveYes
Thanks in advance for any help!
Mar 23 '10 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,768
You are passing the string name itself, with the SQL quote chars (') and the ampersands (&) as the string.

The parameter passed to DoCmd.Close will be literally :
Expand|Select|Wrap|Line Numbers
  1. ' & strModuleNameFull & '
Actually, DoCmd.Close will close the active window if no parameter is passed, so I'd recommend instead :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.Close(Save:=acSaveYes)
Mar 23 '10 #2

P: 24
Excellent, it works!
Thank you very much for the response. Actually I have a drop-down menu with several mathematical functions used later on for columnar calculations. Everytime somebody selects in the menu the function to apply, it opens a short function description form. When the selection is changed in the list, the old description form closes and the new one is opened. Before I couldn't close the opened forms. Now it proceeds smoothly.

Thanks again.

Marcin
Mar 23 '10 #3

NeoPa
Expert Mod 15k+
P: 31,768
I'm very pleased to hear it Marcin :)

By the way, most procedures and other items have an associated Help page that will give you a lot of helpful information. Simply put the cursor in the word you're interested in and press F1. This brings up Context-Sensitive help about the current word.

EG. Press F1 when cursor anywhere within Close.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close
Mar 23 '10 #4

P: 24
Thanks!
This is cool. I didn't notice that I could directly get help this way.

M.
Mar 23 '10 #5

NeoPa
Expert Mod 15k+
P: 31,768
More than cool. I couldn't live without context-sensitive help.

Have fun :)
Mar 23 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.