Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Oct 2001
    Location
    Canada
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable in SQL statement (Word 97-SR2)

    I want to automate the mail merge process by using an input box to get a month number from the user and then running the merge automatically.

    How do I specify the variable name in the SQL statement below so that I could pick up the month number entered in the input box?

    ActiveDocument.MailMerge.DataSource.QueryString = _
    "SELECT * 2001TIME.xls WHERE ((Performance_Review_Month = 10))" _
    & ""

    Any advice or other ideas would be great.

    Joanne

  2. #2
    Star Lounger
    Join Date
    Sep 2001
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable in SQL statement (Word 97-SR2)

    Hello Joanne

    Which input box are you talking about? Do you have a form and code running? If so you would have to write the correct value as string into the field, since the variable would no longer exist, after the form is closed and your macro has finished.

    Please let me know, if my assumption about a form and a macro running is wrong.

    Greetings from Switzerland
    hedgehog

  3. #3
    Lounger
    Join Date
    Oct 2001
    Location
    Canada
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable in SQL statement (Word 97-SR2)

    Hedgehog,
    I should have been a little more specific. In an Autoopen macro for a document, I have an input box asking for a month number. Based on the number ented by the user in the input box, I want to merge just the records from my Excel file from that month and create the document.

    Greetings from Canada! (We were just in your beautiful country in September).

    Joanne

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable in SQL statement (Word 97-SR2)

    Hi Joanne,

    How about the following?

    <pre>Dim strSQL As String


    strSQL = InputBox("Please enter the number of the month to use.", "Month")
    strSQL = "SELECT * 2001TIME.xls WHERE ((Performance_Review_Month = " & strSQL & "))"
    ActiveDocument.MailMerge.DataSource.QueryString = strSQL
    </pre>


    HTH,

    Chris

  5. #5
    Lounger
    Join Date
    Oct 2001
    Location
    Canada
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable in SQL statement (Word 97-SR2)

    Hi Chris,

    Thanks ...that almost worked. I had to declare another variable strSQL1 to contain the "SELECT..." statement and now it runs like a charm.

    Thanks so much for pointing me in the right direction.

    Joanne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •