Fejl meddelse ved makro
Hej.Jeg har et problem. Jeg har en Access form der skal bruges til fletning i et worddokument. Jeg har dertil oprettet en makro. Når jeg kører denne makro får jeg følgende fejl:
"Det indtastede udtryk indeholder et funktionsnavn, MS Office Access ikke kan finde."
Selve makroen ser således ud:
Public Sub MergetoWord()
' This method creates a new document in
' MS Word using Automation
Dim rsCust As New ADODB.Recordset
Dim sSQL As String
Dim WordObj As Word.Application
Dim iTemp As Integer
On Error Resume Next
sSQL = "SELECT * FROM Customers " _
& "WHERE CustomerNumber = " _
& Forms!Orders![CustomerNumber]
rsCust.Open sSQL, CurrentProject.Connection
If rsCust.EOF Then
MsgBox "Invalid customer", vbOKOnly
Exit Sub
End If
DoCmd.Hourglass True
'Try to get a running instance of Word:
Set WordObj = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'An error is thrown if Word is not running,
'so use CreateObject to start up Word:
Set WordObj = CreateObject("Word.Application")
End If
'Make sure the user can see Word:
WordObj.Visible = True
'Warning:
'Specify the correct drive and path to the
'file named Thanks.dotx in the line below.
WordObj.Documents.Add _
Template:="C:\Thanks.dotx", NewTemplate:=False
With WordObj.Selection
.GoTo what:=wdGoToBookmark, Name:="FullName"
.TypeText rsCust![ContactName]
.GoTo what:=wdGoToBookmark, Name:="CompanyName"
.TypeText rsCust![CompanyName]
.GoTo what:=wdGoToBookmark, Name:="Address1"
.TypeText rsCust![Address1]
.GoTo what:=wdGoToBookmark, Name:="Address2"
If IsNull(rsCust![Address2]) Then
.TypeText ""
Else
.TypeText rsCust![Address2]
End If
.GoTo what:=wdGoToBookmark, Name:="City"
.TypeText rsCust![City]
.GoTo what:=wdGoToBookmark, Name:="State"
.TypeText rsCust![State]
.GoTo what:=wdGoToBookmark, Name:="Zipcode"
.TypeText rsCust![Zipcode]
.GoTo what:=wdGoToBookmark, Name:="PhoneNumber"
.TypeText rsCust![PhoneNumber]
.GoTo what:=wdGoToBookmark, Name:="NumOrdered"
.TypeText Forms!Orders![Quantity]
.GoTo what:=wdGoToBookmark, Name:="ProductOrdered"
If Forms!Orders![Quantity] > 1 Then
WordObj.Selection.TypeText Forms!Orders![Item] & "s"
Else
WordObj.Selection.TypeText Forms!Orders![Item]
End If
.GoTo what:=wdGoToBookmark, Name:="FName"
iTemp = InStr(rsCust![ContactName], " ")
If iTemp > 0 Then
.TypeText Left$(rsCust![ContactName], iTemp - 1)
End If
.GoTo what:=wdGoToBookmark, Name:="LetterName"
.TypeText rsCust![ContactName]
DoEvents
WordObj.Activate
.MoveUp wdLine, 6
End With
'Set the Word Object to Nothing to free resources:
Set WordObj = Nothing
DoCmd.Hourglass False
End Sub
Jeg har forsøgt mig med bare at åbne worddokumentet, men det virker heller ikke. Jeg tror det er en opstæningsfejl i Access, men kan bare ikke finde ud af hvor den ligger. Håber der er nogen der kan hjælpe.