Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    macro firing twice (WinXP, OXP)

    We are in the process of having new business management software developed for us. As a part of this new software the requirement is that we be able to generate letters, reports etc as merge documents from the new database. Most of the documents contain macros for the input of variable information not contained in the database.

    The problem I have is that when the documents are called the macros are firing twice. Our software developers have informed me that to enable the data to be extracted from the database they need to run the Open Document method twice, thus causing the macro to fire twice.

    Can anyone give me any clues as to how to overcome this problem?

    cheers
    cheers

    Phil Carter

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro firing twice (WinXP, OXP)

    You could define a static variable, and set/test it in the Document_Open event procedure:

    Private Sub Document_Open()
    Static fRun As Boolean
    If fRun = True Then Exit Sub
    ' code to execute once when document is opened goes here
    ...
    fRun = True
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: macro firing twice (WinXP, OXP)

    Hans

    Thanks for that.

    I don't actually use the Document Open method. To get the macro to run when the document is selected I use the AutoNew method which opens a form for data input via "Private Sub cmdOK_Click()".
    cheers

    Phil Carter

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro firing twice (WinXP, OXP)

    You could use the same technique in AutoNew.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: macro firing twice (WinXP, OXP)

    Hans

    I tried the following

    Sub AutoOpen()

    Static fRun As Boolean
    If fRun = True Then Exit Sub
    frmAS915Letter.Show
    fRun = True
    End Sub

    Didn't work
    cheers

    Phil Carter

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro firing twice (WinXP, OXP)

    Does this work?

    Sub AutoOpen()
    Dim strTest As String
    On Error GoTo ErrHandler
    strTest = ActiveDocument.Variables("WasOpen")
    Exit Sub
    ErrHandler:
    ActiveDocument.Variables("WasOpen") = "Y"
    frmAS915Letter.Show
    End Sub

    If not, I hope someone else will come up with a bright idea.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: macro firing twice (WinXP, OXP)

    Hans

    That wortked just fine.

    Thank you verry much
    cheers

    Phil Carter

Posting Permissions

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