VB code "bolSingle" error

G

Guest

Office 2000

I am using D. Kallal worde merge code and am getting the following error for
when pointing to the following line

Call RidesMergeWord(strDirPath & Me.lstFiles & ".doc", bolSingle)
the error highlights "bolSingle"
with
Compile error:
ByRef argument type mismatch

The folowing references are checked
Visual Basic for applications
Microsoft Access 9.0 library
Microsoft DAO 3.6 Object library
Microsoft data access components installed version
Microsoft Visual basic for applications Extensibility 5.3


Complete code
Dim bolSingle As Boolean

' if in single mode, then we *merge the doc
If IsNull(Me.lstFiles) = False Then
bolSingle = Nz(Me.OpenArgs, "") = "single"

' If bolSingle = False Then
' MsgBox "After document loads. In word select Tools, then select
merge", vbInformation
' '
' End If

Call RidesMergeWord(strDirPath & Me.lstFiles & ".doc", bolSingle)
' DoCmd.Close
Else

MsgBox "You need to select a Word document", vbExclamation, "Word Merge"

End If

Thanks in advance
 
D

Douglas J. Steele

I don't have Albert's code here. How has he declared the arguments for
RidesMergeWord?
 
G

Guest

Doug,

I know this is alot of code but here is the complete module

thanks


Function RidesMergeWord(strDocName As String, _
strDataDir As String, _
Optional strOutDocName As String, _
Optional bolPrint As Boolean = False, _
Optional StrPrinter As String)

' This code takes a word document that has been setup as a MERGE document.
' This merge document is opened, then mailmerge is executed. The original
' document is then closed. The result is a raw word document with no
connectons
' to the merge.txt (a csv source data file).

'Parms:
' strDocName - full path name of word doc (.doc)
' strDataDir - dir (full path) where docuemnts and the
merge.888 file is placed
' strOutDocName - full path name of merged document (saved).
' bolPrint - if true, then output docuemnt is printed - if
strOutDocName is suppled then we close the docuemnt
' strPrinter - sends output to the printer name
'
'
' The above parms are suppled by other routines. You likey should not
need to call this
' routine directly. See the sub called MergeNoPrompts.

' Albert D. Kallal (c) 2001
' (e-mail address removed)
'
Dim WordApp As Object ' running instance of word
Dim WordDoc As Object ' one instance of a word doc
Dim WordDocM As Object ' one instance of a word doc
Dim strActiveDoc As String ' doc name (no path)
Dim lngWordDest As Long ' const for dest, 0 = new doc, 1 =
printer
Dim MyPbar As New clsRidesPBar ' create a instance of our
Progress bar.


MyPbar.ShowProgress
MyPbar.TextMsg = "Launching Word...please wait..."
MyPbar.Pmax = 4 ' 4 steps to inc
MyPbar.IncOne ' step 1....start!

On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error Resume Next

MyPbar.IncOne ' step 2, word is loaded.

Set WordDoc = WordApp.Documents.Open(strDocName)

MyPbar.IncOne ' step 3, doc is loaded

strActiveDoc = WordApp.ActiveDocument.Name
'wordApp.Activate

If bolPrint = False Then
WordApp.Visible = True
WordApp.Activate
WordApp.WindowState = 0 'wdWindowStateRestore
End If

WordDoc.MailMerge.OpenDataSource _
Name:=strDataDir & TextMerge, _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=0, _
Connection:="", SQLStatement:="", SQLStatement1:=""


With WordDoc.MailMerge
.Destination = 0 ' 0 = new doc
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
' .LastRecord = 1
End With
.Execute Pause:=False
End With
Set WordDocM = WordApp.ActiveDocument

MyPbar.IncOne ' step 4, doc is merged
WordDoc.Close (False)

WordApp.Visible = True

If strOutDocName <> "" Then
'wordApp.ActiveDocument.SaveAs strOutDocName
WordDocM.SaveAs strOutDocName

End If

If bolPrint = False Then

WordDocM.Activate

Else

' print this document

If StrPrinter <> "" Then
With WordApp.Dialogs(97) ' 97 - wdDialogFilePrintSetup
.Printer = StrPrinter
.DoNotSetAsSysDefault = True
.Execute
End With
End If


WordDocM.PrintOut
'If strOutDocName <> "" Then
'wordApp.ActiveDocument.Close (False)
' when we print...we *always* close the docuemnt..

WordDocM.Close (False)

'End If

WordApp.Visible = True

End If


MyPbar.HideProgress

Set WordApp = Nothing
Set WordDoc = Nothing
Set WordDocM = Nothing
Set MyPbar = Nothing

DoEvents

' If bolShowMerge = True Then
' WordApp.Dialogs(676).Show 'wdDialogMailMerge
' End If

Exit Function

CreateWordApp:
' this code is here to use the EXISTING copy of
' ms-access running. If getobject fails, then
' ms-word was NOT running. The below will then
' launch word
Set WordApp = CreateObject("Word.Application")
Resume Next

End Function
 
D

Douglas J. Steele

You're passing two pieces of information to the function: strDirPath &
Me.lstFiles & ".doc" and bolSingle. The function, however, is expecting two
string variables: the document name and the data directory, plus up to 3
more optional parameters.

Read the comments at the beginning of the code: it explains what the 5
parameters represent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top