Log in

View Full Version : [SOLVED:] Outlook Custom Form - Links in Textbox



Doodlebug
10-27-2008, 04:19 AM
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 receives 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

CreganTur
10-27-2008, 07:21 AM
It would probably be simpler for you to have a button that utilizes the Application.FollowHyperlink method. It looks like:


Application.FollowHyperlink "http:\\www.vbaexpress.com", , True

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

HTH:thumb

Doodlebug
10-27-2008, 07:24 AM
Hi,

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

CreganTur
10-27-2008, 07:30 AM
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!

Doodlebug
10-27-2008, 07:45 AM
Hi,

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

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 file path 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 careful 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 file path'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 : pray2:

Many thanks in advance, and sorry for all the questions

Neil

CreganTur
10-27-2008, 08:02 AM
....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:

Application.FollowHyperlink Me.txtbox, ,True
now, replace 'txtbox' with the name of the actual textbox that holds the whole filepath to your desired file. This should treat the file path as a hyperlink and follow it (open it).

Doodlebug
10-27-2008, 08:27 AM
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 :help please !!!

Many thanks in advance

Doodlebug
10-29-2008, 04:28 AM
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