jcourtes
asked on
vbscript in outlook - custom form
Hey there,
I'm making a custom form in outlook (based on the message form)
In my form, I have two label objects: uname , and hname
I would like these two labels to become the username, and hostname of the
Here is what I have so far, but gives me errors on line 2 and im not sure why:
Function Item_Open()
Dim HDUsername as string
Dim HDHostname as string
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set HDHostname = WshNetwork.ComputerName
Set HDUsername = WshNetwork.UserName
uname.caption = HDUsername
hname.caption = HDHostname
End Function
Anyone know whats wrong?
I'm making a custom form in outlook (based on the message form)
In my form, I have two label objects: uname , and hname
I would like these two labels to become the username, and hostname of the
Here is what I have so far, but gives me errors on line 2 and im not sure why:
Function Item_Open()
Dim HDUsername as string
Dim HDHostname as string
Set WshNetwork = WScript.CreateObject("WScr
Set HDHostname = WshNetwork.ComputerName
Set HDUsername = WshNetwork.UserName
uname.caption = HDUsername
hname.caption = HDHostname
End Function
Anyone know whats wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you really running this from vbscript, or from outlook vba?
If vbscript, then I'm not sure what the error could be. If it is vba, then change it to
set wshnetwork = createobject("wscript.netw ork")
Even if you are using vbscript, you can remove the qualifying wscript. before createobject
If it is really vba, then you can add the "as string" back to it, making your function:
Function Item_Open()
Dim HDUsername as string
Dim HDHostname as string
Dim WshNetwork as object
Set WshNetwork = CreateObject("WScript.Netw ork")
HDHostname = WshNetwork.ComputerName
HDUsername = WshNetwork.UserName
Set WshNetwork = Nothing
uname.caption = HDUsername
hname.caption = HDHostname
End Function
Matt
If vbscript, then I'm not sure what the error could be. If it is vba, then change it to
set wshnetwork = createobject("wscript.netw
Even if you are using vbscript, you can remove the qualifying wscript. before createobject
If it is really vba, then you can add the "as string" back to it, making your function:
Function Item_Open()
Dim HDUsername as string
Dim HDHostname as string
Dim WshNetwork as object
Set WshNetwork = CreateObject("WScript.Netw
HDHostname = WshNetwork.ComputerName
HDUsername = WshNetwork.UserName
Set WshNetwork = Nothing
uname.caption = HDUsername
hname.caption = HDHostname
End Function
Matt
ASKER
I'm using vbscript in my outlook form. does that mean vba?
When it gets to :
uname.caption = HDUsername
It's telling me "object required"
When it gets to :
uname.caption = HDUsername
It's telling me "object required"
vbscript is a derivitive of VB (as is VBA), though generally used only through .vbs files or .asp pages (an outlook form would usually use VBA, or VB if the form was part of a COM addin). Anyways..
If you're getting 'object required' for that line (and would for the following line too), are your labels truly called "uname" and "hname"?
If so, is your function located in the form's code module? Or is it part of a separate module? If separate, you'll have to refer to the name of the form as well, like
UserForm1.uname.Caption = HDUsername
If you're getting 'object required' for that line (and would for the following line too), are your labels truly called "uname" and "hname"?
If so, is your function located in the form's code module? Or is it part of a separate module? If separate, you'll have to refer to the name of the form as well, like
UserForm1.uname.Caption = HDUsername
ASKER
one thing i've noticed:
I'm putting all the script:
Function Item_Open()
Dim HDUsername
Dim HDHostname
Dim WshNetwork
Dim Testvalue
Set WshNetwork = CreateObject("WScript.Netw ork")
HDHostname = WshNetwork.ComputerName
HDUsername = WshNetwork.UserName
Set WshNetwork = Nothing
MsgBox HDUsername
MsgBox HDHostname 'works up till here.
Testvalue = lbUsername.caption 'this is where the error comes up
MsgBox HDUsername
hd.lbUsername.Caption = HDUsername
hd.lbHostname.Caption = HDHostname
End Function
i've tried adding the parent ? (hd.lbHostname.....)
I don't think i named things correctly. I may have started the form off wrong, but either way, i started with a message form as a base and heavily modified it.
I've created a bunch of labels (lbHostname, lbUsername, lbIPAddress) on the form.
When the form loads, I want the labels to grab their respective values.
Also, will the values get sent along with the form so that they can be read from similar labels on the read side?
If not, what must I keep in mind?
I'm putting all the script:
Function Item_Open()
Dim HDUsername
Dim HDHostname
Dim WshNetwork
Dim Testvalue
Set WshNetwork = CreateObject("WScript.Netw
HDHostname = WshNetwork.ComputerName
HDUsername = WshNetwork.UserName
Set WshNetwork = Nothing
MsgBox HDUsername
MsgBox HDHostname 'works up till here.
Testvalue = lbUsername.caption 'this is where the error comes up
MsgBox HDUsername
hd.lbUsername.Caption = HDUsername
hd.lbHostname.Caption = HDHostname
End Function
i've tried adding the parent ? (hd.lbHostname.....)
I don't think i named things correctly. I may have started the form off wrong, but either way, i started with a message form as a base and heavily modified it.
I've created a bunch of labels (lbHostname, lbUsername, lbIPAddress) on the form.
When the form loads, I want the labels to grab their respective values.
Also, will the values get sent along with the form so that they can be read from similar labels on the read side?
If not, what must I keep in mind?
ASKER
the error:
Object required: 'lbUsername'
Line 12...
Testvalue = lbUsername.caption 'this is where the error comes up
so far I get the poppups with the correct values so I know up until there is working fine..
Just can't seem to find out how to point to the labels i created.
I've even tried:
IPM.Note.SupportRequest.lb Username.C aption
That still doesnt work...
The code up here is also going into the script editor ('view code' from form edit screen)
Should it be going into the visual basic editor - module 1 ?
I'm starting to confuse myself....
Object required: 'lbUsername'
Line 12...
Testvalue = lbUsername.caption 'this is where the error comes up
so far I get the poppups with the correct values so I know up until there is working fine..
Just can't seem to find out how to point to the labels i created.
I've even tried:
IPM.Note.SupportRequest.lb
That still doesnt work...
The code up here is also going into the script editor ('view code' from form edit screen)
Should it be going into the visual basic editor - module 1 ?
I'm starting to confuse myself....
ASKER
should i create custom fields?
ASKER
Set WshNetwork = WScript.CreateObject("WScr