Results 1 to 7 of 7
  • Thread Tools
  1. Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable a command button on send (Word XP)

    I have a word document that a user is required to fill out. Once filled out they click a command button and the document is fired off in an email to another department. This is an old and near redundant use of this document but there have been issues when a document has been received by the end user and they accidentally press the submit button sending the document to their department again!!

    Once this document has been sent via email and is received the command button is disabled so this problem does not occur again. I tried doing this in the past and remember vaguely that it errored out on me as the sub was still running and I could not disable it... any ideas, I was thinking of hiding or reducing the size to 1px by 1px but my Word VBA is reasonable but not that strong.
    Jerry

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Disable a command button on send (Word XP)

    Is this a command button from the Forms toolbar or from the Control Toolbox?

  4. Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable a command button on send (Word XP)

    Hi Hans

    <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15> Looking at my set up ....the Control Toolbox
    Jerry

  5. WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,851
    Thanks
    0
    Thanked 77 Times in 73 Posts

    Re: Disable a command button on send (Word XP)

    You could add a custom document property that stores the date sent. Then your click event can check whether the property exists and either at least query whether they really want to send again (if that might be a possibility) or just display a message telling them it's already been sent. You can also disable the command button when the document is opened if the property exists if you prefer.
    HTH.
    Regards,
    Rory
    Microsoft MVP - Excel.

  6. Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable a command button on send (Word XP)

    The document property idea sounds good....but this is where my knowledge of word VBA comes to a stuttering halt. So let me talk this through to aide my understanding.

    Could I create a text box (possibly hidden) that gets updated with Now() when I click on the command button and then next time if someone clicks it it compares the date and time now and what is in the text box...or have I missed your point?

    I am a bit adverse to putting in a confirmation as this means yet another button they have to press as since Outlook 2K some of them have to confirm again that it should be sent as the Outlook security is set to high as default in my company
    Jerry

  7. WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,851
    Thanks
    0
    Thanked 77 Times in 73 Posts

    Re: Disable a command button on send (Word XP)

    I was thinking something like this:
    <pre>Private Sub cmdSend_Click()
    With ActiveDocument
    .CustomDocumentProperties.Add Name:="send_date", _
    LinkToContent:=False, Type:=msoPropertyTypeDate, Value:=Date
    .Save
    End With
    Me.cmdSend.Enabled = False
    'Code here to send document
    End Sub

    Private Sub Document_Open()
    Dim prp As DocumentProperty
    On Error Resume Next
    Set prp = ActiveDocument.CustomDocumentProperties("send_date ")
    On Error GoTo 0
    Me.cmdSend.Enabled = (prp Is Nothing)
    Set prp = Nothing
    End Sub
    </pre>

    which would disable the commandbutton entirely if the property already exists and also disable it once it has run once so the original user can't send it twice by mistake. You will probably need to add some errorhandling and you may want to change the caption of the command button to indicate why it is disabled (e.g. change it to 'already sent' or something).
    Regards,
    Rory
    Microsoft MVP - Excel.

  8. Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable a command button on send (Word XP)

    Thank you very much Rory,

    That does the job, a small compile error but that is from my original code which I can deal with my side <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>
    Jerry

Posting Permissions

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