B
Bill
I am having some trouble getting the text value of the two text
controls I have added to page 2 of an email for my customer's clients
to us to place orders. The two text controls are named "ClientName"
and "ClientContact". There will be many other controls/fields later
but I am just trying to get a handle on getting the text from a
control here.
I am trying to work through the Microsoft Article:
OL2000: Working with Keywords Fields from VBScript
Article ID: 201099
Sue Mosher suggested this article in another post I read about getting
the value of a text box.
The article shows the following example code:
Sub Commandbutton1_Click()
Set MyPage = Item.GetInspector.ModifiedFormPages("Message")
Set MyControl = MyPage.Controls("TextBox1")
MyControl.Value = Now() & ", " & MyControl.Value
MsgBox MyControl.Value
End Sub
When I run the code, of course, the first error message I get is that
MyPage is undefined.
However, I am not sure what Dim statements to use for MyPage,
MyControl, and Item.
Something I read said that "Item" is a built-in object with a mail
item.
I have the following code in which I have tried to incorporate the
example code above.
Thank you in advance for any help you can give me. I am new at
programming with Outlook so please give me full details of what I need
to do. I have done a lot of reading, but just can't find it.
------------------------------------------------
Private Sub GetMail()
On Error GoTo ErrorHandler
Dim OL As Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Dim ToFolder As Outlook.MAPIFolder
Dim MyMail As MailItem
Dim numErrors As Integer
Dim numCancelledOrders As Integer
Dim numWebOrders As Integer
Dim errPos As Integer
'Declare strings to hold text values of controls in email
Dim strClient As String
Dim strClientName String
errPos = 1
Set OL = New Outlook.Application
Set OLNS = OL.GetNamespace("MAPI")
Set Folder = OLNS.GetDefaultFolder(olFolderInbox)
Set ToFolder = OLNS.GetDefaultFolder(olFolderInbox)
errPos = 2
Set ToFolder = ToFolder.Folders("Test")
MsgBox ToFolder.Items.Count & " items in Test"
errPos = 3
For Each MyMail In Folder.Items
'Process fields
Set MyPage = MyMail.GetInspector.ModifiedFormPages("Message")
strClient = MyMail.UserProperties("ClientName")
strClientContact = MyMail.UserProperties("ClientContact")
PostData "Client: " & strClient & vbCrLf & "Client Contact: " &
strClientContact
End If
errPos = 99
Next MyMail
errPos = 4
PostData "Items processed: " & numItems & vbCrLf & _
"New orders processed: " & numNewOrders & vbCrLf & _
"Cancelled orders processed: " & numCancelledOrders
errPos = 5
Set OL = Nothing
Set OLNS = Nothing
Set Folder = Nothing
Set MyMail = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error in GetMail" & Err.Number & vbCrLf & _
Err.Description & vbCrLf & "errPos: " & errPos & vbCrLf
End Sub
controls I have added to page 2 of an email for my customer's clients
to us to place orders. The two text controls are named "ClientName"
and "ClientContact". There will be many other controls/fields later
but I am just trying to get a handle on getting the text from a
control here.
I am trying to work through the Microsoft Article:
OL2000: Working with Keywords Fields from VBScript
Article ID: 201099
Sue Mosher suggested this article in another post I read about getting
the value of a text box.
The article shows the following example code:
Sub Commandbutton1_Click()
Set MyPage = Item.GetInspector.ModifiedFormPages("Message")
Set MyControl = MyPage.Controls("TextBox1")
MyControl.Value = Now() & ", " & MyControl.Value
MsgBox MyControl.Value
End Sub
When I run the code, of course, the first error message I get is that
MyPage is undefined.
However, I am not sure what Dim statements to use for MyPage,
MyControl, and Item.
Something I read said that "Item" is a built-in object with a mail
item.
I have the following code in which I have tried to incorporate the
example code above.
Thank you in advance for any help you can give me. I am new at
programming with Outlook so please give me full details of what I need
to do. I have done a lot of reading, but just can't find it.
------------------------------------------------
Private Sub GetMail()
On Error GoTo ErrorHandler
Dim OL As Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Dim ToFolder As Outlook.MAPIFolder
Dim MyMail As MailItem
Dim numErrors As Integer
Dim numCancelledOrders As Integer
Dim numWebOrders As Integer
Dim errPos As Integer
'Declare strings to hold text values of controls in email
Dim strClient As String
Dim strClientName String
errPos = 1
Set OL = New Outlook.Application
Set OLNS = OL.GetNamespace("MAPI")
Set Folder = OLNS.GetDefaultFolder(olFolderInbox)
Set ToFolder = OLNS.GetDefaultFolder(olFolderInbox)
errPos = 2
Set ToFolder = ToFolder.Folders("Test")
MsgBox ToFolder.Items.Count & " items in Test"
errPos = 3
For Each MyMail In Folder.Items
'Process fields
Set MyPage = MyMail.GetInspector.ModifiedFormPages("Message")
strClient = MyMail.UserProperties("ClientName")
strClientContact = MyMail.UserProperties("ClientContact")
PostData "Client: " & strClient & vbCrLf & "Client Contact: " &
strClientContact
End If
errPos = 99
Next MyMail
errPos = 4
PostData "Items processed: " & numItems & vbCrLf & _
"New orders processed: " & numNewOrders & vbCrLf & _
"Cancelled orders processed: " & numCancelledOrders
errPos = 5
Set OL = Nothing
Set OLNS = Nothing
Set Folder = Nothing
Set MyMail = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error in GetMail" & Err.Number & vbCrLf & _
Err.Description & vbCrLf & "errPos: " & errPos & vbCrLf
End Sub