473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

HELP Print Custom Forms in Outlook 03 w/User define has error

3
I am not a programmer but i am trying to run the following script i thought i figured out with a book, but i am getting an error.

Here is what i need it to do:
From Outlook 03 Custom Contact Form with User defined fields to go to a word doc and print out.

here is my alert message and not sure what to do or add to fix it:

Object variable not set: 'strMyField'

I worked on this all day yesterday and from this morning till now.. really frustrated...

please help.

thanks in advance

the Script:

Expand|Select|Wrap|Line Numbers
  1. Sub cmdPrint_Click()
  2.    Set oWordApp = CreateObject("Word.Application")
  3.    If oWordApp Is Nothing Then
  4.       MsgBox "Couldn't start Word."
  5.    Else
  6.       Dim oWordDoc
  7.       Dim bolPrintBackground
  8.  
  9.       ' Open a new document
  10.       Set oDoc = oWordApp.Documents.Add("C:\MyForm.dot")
  11.  
  12.       ' Set the first bookmark to the contact's full name
  13.       oDoc.FormFields("FullName").Result = CStr(Item.FullName)
  14.  
  15.       ' Set the second bookmark to the contact's address
  16.       oDoc.FormFields("Address1").Result = CStr(Item.HomeAddressStreet)
  17.  
  18.       ' Set the second bookmark to the contact's address
  19.       oDoc.FormFields("Address2").Result = CStr(Item.HomeAddressCity)
  20.  
  21.       ' Set the second bookmark to the contact's address
  22.       oDoc.FormFields("State").Result = CStr(Item.HomeAddressState)
  23.  
  24.       ' Set the second bookmark to the contact's address
  25.       oDoc.FormFields("Zip").Result = CStr(Item.HomeAddressPostalCode)
  26.  
  27.       ' Set the third bookmark to the contact's home phone
  28.       oDoc.FormFields("Home").Result = CStr(Item.HomeTelephoneNumber)
  29.  
  30.       ' Set the Fourth bookmark to the contact's Email
  31.       oDoc.FormFields("Email").Result = CStr(Item.Email1Address)
  32.  
  33.       ' Set the Fifth bookmark to the contact's Business
  34.       oDoc.FormFields("Business").Result = CStr(Item.BusinessTelephoneNumber)
  35.  
  36.      ' Set the Sixth bookmark to the contact's Business2
  37.       oDoc.FormFields("Business2").Result = CStr(Item.Business2TelephoneNumber)
  38.  
  39.       ' If the form contains user-defined fields, you can use
  40.       ' the following syntax to transfer the contents of a
  41.       ' user-defined field (FieldName) to Word:
  42.  
  43.       strMyField = Item.UserProperties.Find("TextBox31")
  44.       oDoc.FormFields("AccountValue").Result = strMyField
  45.  
  46.       strMyField = Item.UserProperties.Find("TextBox12")
  47.       oDoc.FormFields("Asof").Result = strMyField
  48.  
  49.       strMyField = Item.UserProperties.Find("TextBox32")
  50.       oDoc.FormFields("OutlookUpdated").Result = strMyField
  51.  
  52.       strMyField = Item.UserProperties.Find("TextBox1")
  53.       oDoc.FormFields("ClientName").Result = strMyField
  54.  
  55.       strMyField = Item.UserProperties.Find("TextBox4")
  56.       oDoc.FormFields("RiskTolerance").Result = strMyField
  57.  
  58.       strMyField = Item.UserProperties.Find("TextBox2")
  59.       oDoc.FormFields("ClientIDNumber").Result = strMyField
  60.  
  61.       strMyField = Item.UserProperties.Find("TextBox7")
  62.       oDoc.FormFields("ClientDLNumber").Result = strMyField
  63.  
  64.       strMyField = Item.UserProperties.Find("TextBox8")
  65.       oDoc.FormFields("ClientDLState").Result = strMyField
  66.  
  67.       strMyField = Item.UserProperties.Find("TextBox11")
  68.       oDoc.FormFields("OSTProfileUpdated").Result = strMyField
  69.  
  70.       strMyField = Item.UserProperties.Find("TextBox3")
  71.       oDoc.FormFields("ClientBirthday").Result = strMyField
  72.  
  73.       strMyField = Item.UserProperties.Find("TextBox6")
  74.       oDoc.FormFields("ClientEmploymentStat").Result = strMyField
  75.  
  76.       strMyField = Item.UserProperties.Find("TextBox10")
  77.       oDoc.FormFields("ClientSocialSecurity").Result = strMyField
  78.  
  79.       strMyField = Item.UserProperties.Find("TextBox9")
  80.       oDoc.FormFields("WhenappClientDOD").Result = strMyField
  81.  
  82.       strMyField = Item.UserProperties.Find("TextBox23")
  83.       oDoc.FormFields("Spouse").Result = strMyField
  84.  
  85.       strMyField = Item.UserProperties.Find("TextBox25")
  86.       oDoc.FormFields("SPRiskTolerance").Result = strMyField
  87.  
  88.       strMyField = Item.UserProperties.Find("TextBox22")
  89.       oDoc.FormFields("SpouseIDNumber").Result = strMyField
  90.  
  91.       strMyField = Item.UserProperties.Find("TextBox28")
  92.       oDoc.FormFields("SPDLNumber").Result = strMyField
  93.  
  94.       strMyField = Item.UserProperties.Find("TextBox19")
  95.       oDoc.FormFields("SPDLState").Result = strMyField
  96.  
  97.       strMyField = Item.UserProperties.Find("TextBox29")
  98.       oDoc.FormFields("SPOSTProfileUpdated").Result = strMyField
  99.  
  100.       strMyField = Item.UserProperties.Find("TextBox21")
  101.       oDoc.FormFields("SPBirthday").Result = strMyField
  102.  
  103.       strMyField = Item.UserProperties.Find("TextBox27")
  104.       oDoc.FormFields("SpouseEmploymentSta").Result = strMyField
  105.  
  106.       strMyField = Item.UserProperties.Find("TextBox26")
  107.       oDoc.FormFields("SpouseSocialSecurity").Result = strMyField
  108.  
  109.       strMyField = Item.UserProperties.Find("TextBox24")
  110.       oDoc.FormFields("WhenAppSPDOD").Result = strMyField
  111.  
  112.       strMyField = Item.UserProperties.Find("TextBox13")
  113.       oDoc.FormFields("GroupNumber").Result = strMyField
  114.  
  115.       strMyField = Item.UserProperties.Find("ComboBox1")
  116.       oDoc.FormFields("ReviewType").Result = strMyField
  117.  
  118.       strMyField = Item.UserProperties.Find("TextBox14")
  119.       oDoc.FormFields("ActualReviewDate").Result = strMyField
  120.  
  121.       strMyField = Item.UserProperties.Find("TextBox15")
  122.       oDoc.FormFields("PreviousScheduledApp").Result = strMyField
  123.  
  124.       strMyField = Item.UserProperties.Find("TextBox16")
  125.       oDoc.FormFields("CurrentYearScheduled").Result = strMyField
  126.  
  127.       strMyField = Item.UserProperties.Find("TextBox5")
  128.       oDoc.FormFields("FollowUpAppt").Result = strMyField
  129.  
  130.  
  131.       ' Get the current Word setting for background printing
  132.       bolPrintBackground = oWordApp.Options.PrintBackground
  133.  
  134.       ' Turn background printing off
  135.       oWordApp.Options.PrintBackground = False
  136.  
  137.       ' Print the Word document
  138.       oDoc.PrintOut
  139.  
  140.       ' Restore previous setting
  141.       oWordApp.Options.PrintBackground = bolPrintBackground
  142.  
  143.       ' Close and don't save changes to the document
  144.       Const wdDoNotSaveChanges = 0
  145.       oDoc.Close wdDoNotSaveChanges
  146.  
  147.       ' Close the Word instance
  148.       oWordApp.Quit
  149.  
  150.       ' Clean up
  151.       Set oDoc = Nothing
  152.       Set oWordApp = Nothing
  153.    End If
  154. End Sub
Feb 27 '07 #1
4 2961
Killer42
8,435 Expert 8TB
here is my alert message and not sure what to do or add to fix it: Object variable not set: 'strMyField'
Have you checked the obvious? Maybe you just need to define the variable strMyField. Probably as a string, to judge from a quick glance.
Feb 27 '07 #2
cherub
3
thanks for responding.. i dont program, was just taking a shot at this to print forms for the office.. i really dont understand any of it, trying to make sense to get it to work..

i tried this in the meantime:

Set strMyField = Item.UserProperties

Set strMyField = Item.UserProperties.Find(TextBox31)
* do i have to put Set in the beginning of each one?
oDoc.FormFields(AccountValue).Result = strMyField

**but now it is stopping at: oDoc.FormFields(AccountValue).Result = strMyField
***saying that the object is not found i dont know what this means
Feb 27 '07 #3
Killer42
8,435 Expert 8TB
I think the original code may be alright. Just try adding Dim strMyField As String at the top of the procedure, and see what happens.
Feb 27 '07 #4
cherub
3
expected end of statement line 7
is what is says after what you told me to do.

geeze this is so frustrating for someone who doesnt have a clue (ahhhhh)


would ya charge me for anymore adivice???

i spent to working days with this i have to get it to work, my boss seen what i am trying to do and likes it, if only it would just work.
Feb 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
6
by: Nick Horrocks | last post by:
I have set up a custom error page for 404 errors. However the HTTP status code returned is 302 followed by 200, this causes search engines not to remove old pages from their index. How can I...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
7
by: Flashster | last post by:
My program writes text to a file. Currently the files have a suffix of '.log' . I want to make sure that the user does not attempt to open a file that was not originally created by my program. ...
3
by: Matthew Warren | last post by:
I have the following piece of code, taken from a bigger module, that even as I was writing I _knew_ there were better ways of doing it, using a parser or somesuch at least, but learning how wasn't...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.