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

DDE Access to Word

Status
Not open for further replies.

kcfaa

Programmer
Oct 17, 2006
4
US
First I must admit that when I signed up for forum I indicated that I am a programer...well that is a strech at best I am an end user who has cobbled some code together..

We have an application that links a name/address data base with word to create correspondence.

Orginal application developed years ago as VBA front end and Word Basic Macros in Word, transfered to VBA front end with Access 2000 and Word Macros changed to VBA & Office 2000.

Now as office is getting ready to go to Office 2003 I find that the application does not work with Office 2003. Program is set up to query some basic info from user, then goes out with a DDE command to extract data from database for Word to use. Do I need to dump the DDE and use GetObject?? I am just end user who has put together this correspondence system and don't want to go back to creating documents from scratch.

When try to run get error that DDEINITIATE is failing
Is this related to DDE commands being in a different reference in Office 2003 and Office 2000?

Here is this code we have been using:

Private Sub Generate_Click()
If Forms![WHEAT]![Template] <> "" And Forms![WHEAT]![Names] <> "" Then

Dim Channel As Long
Dim q As String * 1
Dim x As Integer

q$ = Chr$(34)

DoCmd.RunSQL "Update Distinctrow DDE Set DDE.ArptID = " + q$ + Forms![WHEAT]![AirportID] + q$ + ", DDE.RecNum = " + Forms![WHEAT]![Names] + " Where ((DDE.ID=1));"

On Error GoTo ErrorTrap ' if the DDEInitiate fails Error Trap will start Word
Channel = DDEInitiate("Winword", "System")

' the next line runs a macro in MACLIB.DOT that "Restores" the document
' window. This makes the app name on the title bar become "Microsoft Word"
' and that Makes the AppActive command easier to implement. Otherwise you have
' to go through permutations to figure out what is displayed in the Word
' Title Bar. the next 3 lines had been taken out of play put them back to see
'if this helps the appactivate errors that lead to opening a hundred docs or more dj 6/07
DDEExecute Channel, "[FileNew]"
DDEExecute Channel, "[ToolsMacro .Name = " + q$ + "DocRestore" + q$ + ", .Run]"
DDEExecute Channel, "[DocClose 2]"

' Dim appWord As Word.Application
'On Error Resume Next
' Set appWord = GetObject(, "Word.Application")
' If Err.Number <> 0 Then
' Set appWd = CreateObject("Word.Application")
' appWord.Visible = True
' End If



AppActivate "Microsoft Word"
' Hard coding the path for each temlate (rnj 2/14/00)
DDEExecute Channel, "[FileNew .Template = " + q$ + "f:\wheatvb\" + Template + q$ + "]"
'DDEExecute Channel, "[FileNew .Template = " + q$ + CurDir + "\" + Template + q$ + "]"
DDETerminate Channel
GoTo EndSub

 
um, i can run the enclosed code without problems in 2003.

Code:
Sub Macro2()
Dim lngChannel As Long
lngChannel = DDEInitiate("Winword", "System")
DDEExecute lngChannel, "[FileNew]"
DDETerminate lngChannel
End Sub

what error are you getting where?


mr s. <;)

 
I'm thinking that you might just not have the correct reference(s) set, as misterstick stated that it worked on his computer.

Perhaps you need to make sure that:
Code:
Microsoft Word xx.x Object Library

Is selected...

Or else:
Code:
Microsoft Office xx.x Object Library

Is selected.

In the VBA window, access References by going to:
Tools menu-> References

Then locate the correct reference(s) and make sure it/they are checked.

--

"If to err is human, then I must be some kind of human!" -Me
 
of course, my code only worked because word was already running.

it looks like your code used to check to see that this was true.

add these lines (from your code) before you call DDEInitiate().

Code:
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
  Err = 0
  Set appWord = CreateObject("Word.Application")
  If Err.Number <> 0 Then
    appWord.Visible = True
  Else
    End ' Stop processing since there's no Word
  End If
End If
On Error Goto 0 ' or whatever your error checking was

mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top