Hi Graham - thanks for replying
This is the code I have attached to a combobox within my word document (See code below).
However, whenever I try saving the word document as Rich Text Format, it warns me that all macros will be lost! It works ok if I save it as .doc format.
Is it possible with .rtf?
Private Sub Document_Open()
On Error GoTo Document_Open_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OL
"Data Source=C:\db\Names.mdb"
rst.Open "SELECT DISTINCT [StaffNames] FROM tblNames ORDER BY [StaffNames];", _
cnn, adOpenStatic
rst.MoveFirst
With Me.ComboBox1
.Clear
Do
.AddItem rst![StaffNames].Value
rst.MoveNext
Loop Until rst.EOF
End With
Document_Open_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
Document_Open_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume Document_Open_Exit
End Sub
Main Topics
Browse All Topics





by: GrahamSkanPosted on 2008-07-02 at 06:13:14ID: 21915971
By design, most macros reside in the document's template which remains attached even if the document is saved as rtf. Make sure that then code is in the template, and that it (or a copy) are accessible by the user.