Consulting

Results 1 to 8 of 8

Thread: Solved: Outlook Custom Form - Links in Textbox

  1. #1

    Solved: Outlook Custom Form - Links in Textbox

    Hi,

    I have been tasked to develop a custom form which registers contracts. The recipient of this email form needs to have links to various workbooks (.xls, .doc & .pdf files). I have added some functionality to the template, where the sender clicks on a button, browses to the file (that they want to send the link of), using the commondialog box. When the sender clicks open, the full filepath is inserted into a textbox.

    The code i have used is:
    sub cmdBrowse1_Click
    sSaveMessageClass = Item.MessageClass
    Set objDialog = CreateObject("UserAccounts.CommonDialog") 
    objDialog.Filter = "Excel Spreadsheets|*.xls"
    objDialog.FilterIndex = 1 
    'objDialog.InitialDir = "W:\" 
    intResult = objDialog.ShowOpen 
    If intResult = 0 Then 
    exit sub 
    Else 
    Item.UserProperties.Find("txtBrowse1").Value = "<file://" & objDialog.FileName & ">"
    End If 
    Item.MessageClass = sSaveMessageClass
    end sub
    


    Ideally, i would like this task to insert a hyperlink to the file, so that when the recipient recieves the email, all they have to do is click on the textbox to open the document, but i cannot figure it out. I have also tried adding a click event for the corresponding box on the read page, but i cannot get it work.

    Any ideas?

    Thanks in advance
    Neil

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    It would probably be simpler for you to have a button that utilizes the Application.FollowHyperlink method. It looks like:

    [VBA]Application.FollowHyperlink "http:\\www.vbaexpress.com", , True[/VBA]

    The True tells VBA to open the hyperlink in a new window.

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    Hi,

    Thanks for the reply. With this method, can i still pass the variable contaiing the filepath rather than having it hard coded?

  4. #4
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Quote Originally Posted by Doodlebug
    Hi,

    Thanks for the reply. With this method, can i still pass the variable contaiing the filepath rather than having it hard coded?
    Yes, you can. If you need help with that, let us know.


    BTW, welcome to the forums- always good to have new members!
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  5. #5
    Hi,

    Thanks for the offer, and it feels good to be welcomed aboard

    I think i am getting a bit confused. I am very proficient in Office VBA (mainly Excel), and i appreciate that Outlook forms are coded using VBscript. I think that's where my confusion comes from.

    Apologies in advance if i sound dumb (or if i ask a really obvious question) i'm hoping it will become easier with time etc....

    What i am trying to achieve is this:

    I have a custom form with multiple fields which the originator completes (these are either textboxes or comboboxes) - no problem. Then i have 3 textboxes which i need filled in by using the commondialog box. I can get the textboxes completed with the relevant filepath, but i cannot get it to make it into a hyperlink. The code i am using behind the 'Insert Filepath' command button is this:
    sub cmdBrowse1_Click
    sSaveMessageClass = Item.MessageClass
    Set objDialog = CreateObject("UserAccounts.CommonDialog") 
    objDialog.Filter = "Excel Spreadsheets|*.xls"
    objDialog.FilterIndex = 1 
    'objDialog.InitialDir = "W:\" 
    intResult = objDialog.ShowOpen 
    If intResult = 0 Then 
    exit sub 
    Else 
    Item.UserProperties.Find("txtBrowse1").Value = "<file://" & objDialog.FileName & ">"
    End If 
    Item.MessageClass = sSaveMessageClass
    end sub
    
    I have a 3 buttons on my form named cmdBrowse1, 2 & 3 respectively, which insert the filepath into 3 user defined textboxes names txtBrowse1, 2 & 3 respectively, using 2 more variations of the above code.

    Reading up about Outlook forms, I have to be carefule about 'one-off'-ing the form? When i publish it (in to Personal Forms Library) for testing, the field i have added called message class reads IPM.Note Contract New Neil, however, when i complete it and send it to myself, the message class field reads IPM.Note. I don't this is correct, but i don't know where to start looking.

    ....and another questions (very sorry). I cannot seem to use a textbox_click event to make the filepath's textbox into a clickable link to open the document.

    I know this looks like i am asking for someone else to do my work, but it's not. I would really like to learn how to correct the mistakes or write it correctly, so that it works

    Many thanks in advance, and sorry for all the questions

    Neil

  6. #6
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    ....and another questions (very sorry). I cannot seem to use a textbox_click event to make the filepath's textbox into a clickable link to open the document.
    What you can do is put this code behind your textbox OnClick event:
    [VBA]Application.FollowHyperlink Me.txtbox, ,True[/VBA]
    now, replace 'txtbox' with the name of the actual textbox that holds the whole filepath to your desired file. This should treat the filepath as a hyperlink and follo wit (open it).
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  7. #7
    Thanks for the very quick reply...

    My next problem, is that none of the code is present when the form is recieved by the recipient. the button (cmdBrowse1) which opens the commondialog box doesn't work, nor does the textbox click event.

    I think it's something to do with one-off - ing, but i haven't a clue where to look please !!!

    Many thanks in advance

  8. #8
    Found a solution, and thought i would post the answer, in case anyone else needs this functionality.

    Firstly, i added this VBScript code to change the message class if the class changed during completion:

    Sub Item_PropertyChange(ByVal Name)
        Select Case Name
            Case "MessageClass"
            Item.MessageClass = "IPM.Note.<form name>" 
        End Select
    End Sub
    


    Secondly, on the edit compose page, i used this code for the browse button, to complete the textbox with the full filepath:

    sub cmdBrowse1_Click
        Set objDialog = CreateObject("UserAccounts.CommonDialog") 
        objDialog.Filter = "All Files|*.*"
        objDialog.FilterIndex = 1 
        intResult = objDialog.ShowOpen 
        If intResult = 0 Then 
            exit sub 
        Else 
            Item.UserProperties.Find("txtBrowse1").Value = "file:\\" & objDialog.FileName
        End If 
    end sub
    


    I used a button named cmdBrowse1 with a textbox named txtBrowse1 with a user-defined field name of txtBrowse1 also.

    ...and lastly, on the read page, i used this code:

    sub cmdBrowse1g_Click
        dim objShell
        set objShell = CreateObject("Shell.Application") 
        MyValue = Item.UserProperties("txtBrowse1") 
        str = MyValue
        objShell.ShellExecute str, "", "", "open", 1 
        set objShell = nothing
    end sub
    


    ...on a button named cmdBrowse1g to open the document file path contained in the textbox txtBrowse1.

    Hope this may be of help to someone else.

    BR
    Neil

Posting Permissions

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