Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save ComboBox values in Word Document

Status
Not open for further replies.

JohnnyLong

Programmer
Sep 27, 2002
97
GB
I have a Word 2000 document with 8 comboboxes. I want to email this document to a client for them to select there values and email the document back. How do I save the values they have chosen in the comboboxes? I populate the combos in Document_Open and then:

Dim oProp As DocumentProperty

' Check if property exists
If Me.CustomDocumentProperties.Count > 0 Then
Set oProp = Me.CustomDocumentProperties.Item("SelLength")
If Not oProp Is Nothing Then bPropExists = True
End If

If Not bPropExists Then
' Add property to collection
Me.CustomDocumentProperties.Add "SelLength", False, _
msoPropertyTypeString, "Day(s)"
' set default selection
cboContractLength.ListIndex = 0
Else
For iCtr = 0 To cboContractLength.ListCount - 1
If cboContractLength.List(iCtr) = oProp.Value Then
cboContractLength.ListIndex = iCtr
Exit For
End If
Next
End If

This works fine for the first combobox and the value is saved. However if I replicate the code for the second combo I get 'Invalid Procedure call or argument' in Document_Close
sStartDay = cboStartDay.Value
Me.CustomDocumentProperties("SelDay") = sStartDay

If I'm on the right lines, can I use CustomDocumentProperties as a collection? Confused.
 
Hi JohnnyLong,

I'm not clear about what code you have in which routine (open and close), but you would appear to have a problem in the posted code which would cause the error you quote.

Checking that you have some custom properties is not sufficient to then allow you to try and access one which doesn't exist ..

Set oProp = Me.CustomDocumentProperties.Item("SelLength")

.. will error out if "SelLength" doesn't exist; you must trap the error. At its simplest you could just ignore it ..

Code:
   If Me.CustomDocumentProperties.Count > 0 Then
Code:
On Error Resume Next
Code:
      Set oProp = Me.CustomDocumentProperties.Item("SelLength")
Code:
On Error GoTo 0
Code:
      If Not oProp Is Nothing Then bPropExists = True
   End If

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top