String variable in DoCmd.Close

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mabrynda
    New Member
    • Jan 2010
    • 24

    String variable in DoCmd.Close

    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:

    Code:
    strModuleNameFull = "frmFunctMod1"
    Debug.Print "check string name", strModuleNameFull
    DoCmd.Close acForm, " ' &  strModuleNameFull & ' ", acSaveYes
    Thanks in advance for any help!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #2
    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 :
    Code:
    ' & strModuleNameFull & '
    Actually, DoCmd.Close will close the active window if no parameter is passed, so I'd recommend instead :
    Code:
    Call DoCmd.Close(Save:=acSaveYes)

    Comment

    • mabrynda
      New Member
      • Jan 2010
      • 24

      #3
      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

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #4
        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.
        Code:
        DoCmd.[I]Close[/I]

        Comment

        • mabrynda
          New Member
          • Jan 2010
          • 24

          #5
          Thanks!
          This is cool. I didn't notice that I could directly get help this way.

          M.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #6
            More than cool. I couldn't live without context-sensitive help.

            Have fun :)

            Comment

            Working...