Using Object Data in VBScript

G

Gary Newport

I have asked this elsewhere but thought it would be better as an identifiable
question...

How can I use the value of a textbox elsewhere (such as the subject textbox)
when sending the message?

Also, can I do the same to enable/disable a control?

Function Item_Send()

dim mySubject
dim myTextbox1

Set mySubject = txtSubject
Set myTextbox1 = txtTextbox1
mySubject.Value = "Round Robin for " & myTextbox1.Value

End Function
 
G

Gary Newport

I have used the property values set in design wherever possible but I need
things to change as the form is completed/sent.

I have now realised that I am using the textbox name, rather than the bound
name so have changed the one code to...

Function Item_Send()

dim mySubject
dim myStudent

Set mySubject = Subject
Set myStudent = Student
mySubject.Value = mySubject.Value & myStudent.Value

End Function

However, when I run this form I get the error:

Microsoft VBScript runtime error: Object required: '[string: "Round Robin
for "]'

Now the text given is contained within the bound field of Subject and this
appears as the stored property when I undertake a watch. So the object is
being recognised by the editor but not being transferred to the new set
variable mySubject.

Equally, Student is not receiving it's value, even though it has been
entered into the field.

I need this to update the Subject field just before being sent.
 
S

Sue Mosher [MVP-Outlook]

Where do the object variables "Subject" and "Student" come from? Your code
snippet doesn't that.

As explained in the article I suggested, the value of the Subject property
of any Outlook item, is usually returned and set in form code with
Item.Subject. Therefore, your could should be something more like:

Item.Subject = Item.Subject & <some new value>

Where <some new value> comes from depends on the information that's missing
from your code snippet -- how the Student object variable is derived. Going
solely on the error message, it looks like Student is not an object variable
at all, but instead is a string variable, in which case, the statement to
update the subject would be:

Item.Subject = Item.Subject & Student
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Gary Newport said:
I have used the property values set in design wherever possible but I need
things to change as the form is completed/sent.

I have now realised that I am using the textbox name, rather than the bound
name so have changed the one code to...

Function Item_Send()

dim mySubject
dim myStudent

Set mySubject = Subject
Set myStudent = Student
mySubject.Value = mySubject.Value & myStudent.Value

End Function

However, when I run this form I get the error:

Microsoft VBScript runtime error: Object required: '[string: "Round Robin
for "]'

Now the text given is contained within the bound field of Subject and this
appears as the stored property when I undertake a watch. So the object is
being recognised by the editor but not being transferred to the new set
variable mySubject.

Equally, Student is not receiving it's value, even though it has been
entered into the field.

I need this to update the Subject field just before being sent.

Sue Mosher said:
Control values are generally the wrong approach. Instead, use the property
values, e.g. Item.Subject. See http://www.outlookcode.com/article.aspx?ID=38
 
G

Gary Newport

Sorry, should have explained better...

I have a textbox called txtSendStudent (stupid name but running out of ideas
at present). I have created a field called Student and have bound the textbox
to this field.

I now have the code you gave me and it works...sort of.

If I fill out the initial email and click SEND the message is sent with the
subject being "Round Robin for" being shown. When I forward the form back
then the subject changes to "Round Robin for <student name>".

The desired effect but I want it to change the subject before the initial
send and not once the form is returned.
 
S

Sue Mosher [MVP-Outlook]

So, you'll need something in your Item_Send event handler to distinguish new
items from forwarded items, right? Maybe the FW: prefix on the subject would
be sufficient?

Why do you think your control name is stupid? As long as it makes sense to
you (and will still make sense 6 months from now when you update the code), a
control name can be anything you like.
 
G

Gary Newport

One day I'll explain with all relevant details contained. :eek:)

As I have stated, I have a textbox called txtSendStudent bound to a field
called Student.

I would like the email to be sent with the subject field containing the
words "Round Robin for <student name>" to make it clear to the recipients who
the round robin is about.

What I NEGLECTED to state was that the default text is "Round Robin for" is
the default text for my Subject field. So, the intially received email is
only showing the default value of the Subject field textbox. Only on the
return send (technically known as FORWARD) does the Subject field NOW contain
the text I want.

I therefore need the code to alter the subject field BEFORE sending the email.
 

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