Using Environment Variables

E

Eka1618

Hello,

I am trying to creake a hyperlink in an e-mail message that will open a file
on the users desktop. I need to use an environment variable so that it will
link to the user who opens up the message.

If I leave out the <a href> tag, the string (strPath) displays the path I am
looking for: C:\Documents and Settings\EMM\Desktop|EngFE.accdb

I am not sure why making strPath the link in my hyperlink is causing the
string to change its value. I dont think it is changing value, but when I
receive the e-mail the link is changed to: C:\Documents

Here is my code:

Public Sub conductorEMail(frm As Form)
'Send an e-mail using the outlook application object...
'version 1.0
'1.0: Initial version.

Dim outOutlookInstance As Outlook.Application
Dim maiMessage As MailItem
Dim lngCounter As Long
Dim strArray() As String
Dim emName As String, varItem As Variant
Dim emailBody As String
Dim emailSubject As String
Dim strPath As String

strPath = "C:\Documents and Settings\" & Environ("USERNAME") &
"\Desktop\EngFE.accdb"

On Error GoTo SendEMail_Error

'Create the Outlook instance...
Set outOutlookInstance = CreateObject("Outlook.Application")

emailSubject = "New Test Assigned"

emailBody = "Hello, <br><br>" & _
"The product test request for Request Number: " & "<b><font color =
red>" & frm.REQUEST_NO.Value & "</font></b>" & _
" has been Accepted by the Tech Team Leader. <br><br>" & _
"You have been assigned:<br><br>" & _
"Test Queue # " & " <b><font color = red>" & frm.QID.Value &
"</font></b><br>" & _
"Test Type : " & "<b><font color = red>" & frm.TEST_TYPE.Value &
"</font></b> <br><br>" & _
"Please log into the <a href = " & strPath & ">Product Engineering Test
Database</a> to enter test results once test has been completed.<br><br>" & _
"Thank You!"

'Create the mail message...
Set maiMessage = outOutlookInstance.CreateItem(olMailItem)
With maiMessage
.To = CurrentDb.Properties("ConductorsEmail")
.SentOnBehalfOfName = CurrentDb.Properties("RequesteeEmail")
.Subject = emailSubject
.HTMLBody = "<h2 align = center><b><font color = red>Test Queue
Assigned (Test Conductors Next Action)<align></font></b></h2><br><br>" &
emailBody

'Send the message...
.Send

End With

'Clear the objects...
Set maiMessage = Nothing
Set outOutlookInstance = Nothing


SendEMail_Error:
If Err.Number <> 0 Then
MsgBox Err.Number & ": " & Err.description, vbCritical, "SendEMail"
End If

End Sub



If anyone has any suggestions, please let me know! Thank You!
 
E

Eka1618

The link that displays in the e-mail is:
file:///C:\Documents

I do not know why 'file:///' is added to the link...

Please let me know if you have any suggestions. Thanks again!
 
E

Eka1618

Thank you for the link. I am getting closer, but I still cannot find the
correct character to user to substitute for a space. The link was saying to
use +, but this method did not work.

Now that I know it is a space issue I might be able to find more information
about the character I need.

If you know of any, please send it my way :)

Thanks again!
 
E

Eka1618

I ended up solving my problem by using the replace() function. For anyone who
is interested this is what I did:


Dim dbLink As String

dbLink = "file://C:/Documents and Settings/" & Environ("USERNAME") &
"/Desktop/Eng startup.lnk"
dbLink = Replace(dbLink, " ", "%20")
 
S

Stefan Hoffmann

hi,
dbLink = "file://C:/Documents and Settings/" & Environ("USERNAME") &
"/Desktop/Eng startup.lnk"
dbLink = Replace(dbLink, " ", "%20")
You should use the USERPROFILE environment variable as "C:/Documents and
Settings/" is not necessarily the base drive and/or path for your user
profile.


mfG
--> stefan <--
 
E

Eka1618

Yes I could use that as well, my main concern was to insert the space in this
link.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top