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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DDE Problems Word and Access 2000

Status
Not open for further replies.

kenaida

Programmer
Jul 9, 2001
3
GB
Hi there, I am trying to place a text string into a bookmarked position in a word document and can not get it to work. There seems to be little or no examples of it on the net. Please help. I have tried the following code:

Private Sub Command0_Click()
Dim chan
Shell ("winword.exe"), 1
chan = DDEInitiate("WinWord", "system")
DDEPoke chan, "\Startofdoc", "Test message"
DDETerminate chan

End Sub

Using this code i get this error :

The application can not perform the DDE function that you attempted.
 
It is much clearer to use the Word objects than DDE unless it is legacy software. I previously used DDE and found it slow and unintuitive and poorly documented. You might want to convert.

Steve King

Call CreateWordFile(UCase(DialogMessage.strFilename), DialogMessage.strTitle, DialogMessage.strIRNarrative, DESIGN_TEMPLATE)

Public Sub CreateWordFile(strDocName As String, strTitle As String, _
strNarrative As String, Optional varTemplateName)
' Ref: Microsoft Office 97 Visual Basic Programming Guide, Page 175
On Error GoTo notloaded

Dim oWordApp As Word.Application
Dim MyDoc As Word.Document
Dim oCell As Cell
Dim cnt As Integer
Dim strTemplate As String

Set oWordApp = GetObject(, "Word.Application.8")
oWordApp.Visible = True
If IsMissing(varTemplateName) Then
oWordApp.Documents.Add
Else
oWordApp.Documents.Add Template:=varTemplateName, NewTemplate:=False
End If

Set MyDoc = oWordApp.ActiveDocument
If InStr(1, varTemplateName, "Analysis") Then
'oWordApp.Run "NewAnalysis"
MyDoc.Bookmarks("DateAnalyzed").Select
oWordApp.Selection.Text = Format(Date, "dd-mmm-yy")
MyDoc.Bookmarks("IncidentReport").Select
oWordApp.Selection.Text = Mid$(strDocName, 3, 2) & "-" & Mid$(strDocName, 5, 4)
MyDoc.Bookmarks("txtIRTitle").Select
oWordApp.Selection.Text = strTitle
MyDoc.Bookmarks("Analysis").Select
oWordApp.Selection.Text = strNarrative
MyDoc.SaveAs FileName:="f:\groups\sdv\dmats\analysis\" & strDocName
ElseIf InStr(1, varTemplateName, "Design") Then
MyDoc.Bookmarks("DateReviewed").Select
oWordApp.Selection.Text = Format(Date, "dd-mmm-yy")
MyDoc.Bookmarks("IncidentReport").Select
oWordApp.Selection.Text = Mid$(strDocName, 3, 2) & "-" & Mid$(strDocName, 5, 4)
MyDoc.Bookmarks("txtIRTitle").Select
oWordApp.Selection.Text = strTitle
'Set a Checkbox value
'MyDoc.FormFields("Check9").CheckBox.Value = True
MyDoc.Bookmarks("DesignNotes").Select
oWordApp.Selection.Text = strNarrative
MyDoc.SaveAs FileName:="f:\groups\sdv\dmats\design\notes\" & strDocName
End If

strTemplate = oWordApp.Templates.Creator

Exit_Proc:
Exit Sub

notloaded:
If Err.Number = 429 Then
Set oWordApp = CreateObject("Word.Application.8")
Resume Next
ElseIf Err.Number = 5137 Then
MsgBox "Template " & varTemplateName & " does not exist."
Else
MsgBox Err.Number & ", " & Err.Description
End If
GoTo Exit_Proc

End Sub

Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top