remcop1989
Gebruiker
- Lid geworden
- 29 mrt 2012
- Berichten
- 492
Voor een mailmerge met Word (2003) heb ik de volgende code:
Deze code heb ik van deze website: http://www.tek-tips.com/faqs.cfm?fid=3237 en uiteraard zelf aangepast naar mijn database.
Ik krijg nu de volgende foutmelding: "Een door de gebruiker gedefinieerd gegevenstype is niet gedefinieerd"
Deze krijg ik op de volgende regels:
Wat is er mis? Ik kom er niet achter.
Code:
Private Sub SetQuery(strQueryName As String, strSQL As String)
On Error GoTo ErrorHandler
'set the query from which the merge document will pull its info
Dim qdfNewQueryDef As QueryDef
Set qdfNewQueryDef = CurrentDb.QueryDefs(strQueryName)
qdfNewQueryDef.SQL = strSQL
qdfNewQueryDef.Close
RefreshDatabaseWindow
Exit Sub
ErrorHandler:
MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error"
Exit Sub
End Sub
Private Sub offertemaken_Click()
'creates an SQL statement to be used in the query def
On Error GoTo ErrorHandler
' user enters a zip code in a text box on the form;
' the query's criteria is set to pull records for
'that zip code
Dim strOffertenummer As String
strOffertenummer = Offertenummer.Value
Dim strSQL As String
'replace the SQL statement below with the SQL statement
'from your query. This sample shows how to use single quotes
'to incorporate string values from the form's fields
'into the SQL statement. For dates, use # instead of the
'single quotes
strSQL = "SELECT Klanten.Bedrijfsnaam, Offertes.[Voornaam klant], Offertes.[Achternaam klant], Klanten.Postadres, Klanten.Postcode, Klanten.PostPlaats, Klanten.Land, Offertes.[Telefoonnummer klant], Offertes.[E-mailadres klant], Offertes.Betreft, Offertes.[Datum van opstellen], Offertes.[Plaats van opstellen], Offertes.Offertenummer, Offertes.[Datum transport bezorgen], Offertes.[Datum transport ophalen], Offertes.Huurperiode, Offertes.Afleveradres
FROM Klanten INNER JOIN Offertes ON Klanten.KlantID=Offertes.KlantID;"
Dim strDocumentName As String 'name of the Word template document
strDocumentName = "\offerte sjabloon huur nederlands.doc"
'use your template document name above
Call SetQuery("Query1", strSQL)
'use your query name above
Dim strNewName As String 'name to use when saving
'the merged document
'this next line of code makes the document name pattern
'like this: Custom Labels January 11, 2005.doc
strNewName = "Off- " & Offertenummer)
'use your file name pattern above
Call OpenMergedDoc(strDocumentName, strSQL, strNewName)
Exit Sub
ErrorHandler:
MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error"
Exit Sub
End Sub
Private Sub OpenMergedDoc(strDocName As String, strSQL As String, strMergedDocName As String)
On Error GoTo WordError
'opens an instance of Word, opens a merge template which has its data source
'already linked to a query in the database,
'optional code merges the template to a new document,
'saves the merged file with a descriptive name,
'then closes the merge template
'Set the directory for any labels generated
Const strDir As String = "S: \Contacts"
'use your directory and folder name above
Dim objWord As New Word.Application
Dim objDoc As Word.Document
objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strDir & strDocName)
' Make Word visible so that if any errors occur,
' you can close the instance of Word manually
objWord.Application.Visible = True
'*optional code to merge to a new document, save the merged document, and close the template goes here*
'release the variables
Set objWord = Nothing
Set objDoc = Nothing
Exit Sub
WordError:
MsgBox "Err #" & Err.Number & " occurred." & Err.Description, vbOKOnly, "Word Error"
objWord.Quit
End Sub
Deze code heb ik van deze website: http://www.tek-tips.com/faqs.cfm?fid=3237 en uiteraard zelf aangepast naar mijn database.
Ik krijg nu de volgende foutmelding: "Een door de gebruiker gedefinieerd gegevenstype is niet gedefinieerd"
Deze krijg ik op de volgende regels:
Code:
Dim objWord As New Word.Application
Dim objDoc As Word.Document
Wat is er mis? Ik kom er niet achter.