I am the registrar for a large conference and am having trouble with the coding in an Access 2000 database.
This code is meant to pull the registrations into the attendee table so I can produce Confirmation Letters, but it isn't working
It does run the WORD mail merge function, but it isn't pulling the registration information, so the letters are missing this very important information.
Can anyone look at this code and tell me where the snafu is and how to fix it
I don't write code.
Thanks,
Laura
Beginning Code:
Code for Process Confirmation Letters…..
Option Explicit
Option Compare Database
Private Sub Form_Activate()
Dim dao_confirm_wsp As DAO.Workspace
Dim dao_confirm_rs As DAO.Recordset
Dim dao_confirm_db As DAO.Database
Dim confirm_sql As String
Dim loop_ctr As Integer
Dim strDocumentName As String
' First, update all attendee records which have null in confimation date
Set dao_confirm_db = CurrentDb
Set dao_confirm_wsp = CreateWorkspace("", "admin", "", dbUseJet)
confirm_sql = "SELECT Attendees.* " & _
"FROM Attendees " & _
"WHERE (((Attendees.ConfirmationDate) Is Null));"
Set dao_confirm_rs = dao_confirm_db.OpenRecordset(confirm_sql)
If Not (dao_confirm_rs.BOF) Then
' If (dao_confirm_rs.BOF) Then
' MsgBox "There are no registrations ready to be confirmed.", vbCritical
' dao_confirm_rs.Close
' Set dao_confirm_rs = Nothing
' Set dao_confirm_wsp = Nothing
' Set dao_confirm_db = Nothing
' Exit Function
' Else
dao_confirm_rs.MoveFirst
Do Until dao_confirm_rs.EOF
' For each attendee record
dao_confirm_rs.Edit
[dao_confirm_rs]![ConfirmationDate] = Date
[dao_confirm_rs]![BreakOutEventName1] = " "
[dao_confirm_rs]![BreakOutEventDesc1] = " "
[dao_confirm_rs]![BreakOutEventName2] = " "
[dao_confirm_rs]![BreakOutEventDesc2] = " "
[dao_confirm_rs]![BreakOutEventName3] = " "
[dao_confirm_rs]![BreakOutEventDesc3] = " "
[dao_confirm_rs]![BreakOutEventName4] = " "
[dao_confirm_rs]![BreakOutEventDesc4] = " "
[dao_confirm_rs]![BreakOutEventName5] = " "
[dao_confirm_rs]![BreakOutEventDesc5] = " "
[dao_confirm_rs]![BreakOutEventName6] = " "
[dao_confirm_rs]![BreakOutEventDesc6] = " "
[dao_confirm_rs]![BreakOutEventName7] = " "
[dao_confirm_rs]![BreakOutEventDesc7] = " "
[dao_confirm_rs]![BreakOutEventName8] = " "
[dao_confirm_rs]![BreakOutEventDesc8] = " "
[dao_confirm_rs]![BreakOutEventName9] = " "
[dao_confirm_rs]![BreakOutEventDesc9] = " "
[dao_confirm_rs]![BreakOutEventName10] = " "
[dao_confirm_rs]![BreakOutEventDesc10] = " "
[dao_confirm_rs]![MailingAddress] = " "
[dao_confirm_rs]![MailingCity] = " "
[dao_confirm_rs]![MailingState] = " "
[dao_confirm_rs]![MailingZip] = " "
Dim dao_get_regis_wk As DAO.Workspace
Dim dao_get_regis_rs As DAO.Recordset
Dim dao_get_regis_db As DAO.Database
Dim get_regis_sql As String
Set dao_get_regis_db = CurrentDb
Set dao_get_regis_wk = CreateWorkspace("", "admin", "", dbUseJet)
get_regis_sql = "SELECT Registration.*, Events.EventName, Events.EventDescription, Events.EventTypeID, Events.EventID as EvtID " & _
"FROM Registration INNER JOIN Events ON Registration.EventID = Events.EventID " & _
"WHERE Registration.AttendeeID = " & [dao_confirm_rs]!AttendeeID & _
" ORDER BY Events.EventName"
' get_regis_sql = "SELECT Registration.* " & _
' "FROM Registration " & _
' "WHERE Registration.AttendeeID = " & [dao_confirm_rs]!AttendeeID
Set dao_get_regis_rs = dao_get_regis_db.OpenRecordset(get_regis_sql)
loop_ctr = 0
If Not (dao_get_regis_rs.BOF) Then
dao_get_regis_rs.MoveFirst
Do Until dao_get_regis_rs.EOF
If loop_ctr < 10 Then
'
Dim dao_get_event_wk As DAO.Workspace
Dim dao_get_event_rs As DAO.Recordset
Dim dao_get_event_db As DAO.Database
Dim get_event_sql As String
Set dao_get_event_db = CurrentDb
Set dao_get_event_wk = CreateWorkspace("", "admin", "", dbUseJet)
get_event_sql = "SELECT Events.EventName, Events.EventDescription, Events.EventTypeID, Events.EventID, [Event Types].EventType AS EvtDsc " & _
"FROM [Event Types] INNER JOIN Events ON [Event Types].EventTypeID = Events.EventTypeID " & _
"WHERE Events.EventID = " & [dao_get_regis_rs]!EvtID
' get_event_sql = "SELECT Events.EventName, Events.EventDescription, Events.EventTypeID, Events.EventID, [Event Types].EventType AS EvtDsc " & _
' "FROM [Event Types] INNER JOIN Events ON [Event Types].EventTypeID = Events.EventTypeID " & _
' "WHERE Events.EventID = " & [dao_get_regis_rs]!EventID
Set dao_get_event_rs = dao_get_event_db.OpenRecordset(get_event_sql)
If Not (dao_get_event_rs.BOF) Then
dao_get_event_rs.MoveFirst
If ([dao_get_event_rs]![EvtDsc] = "BreakOut Session") Then
loop_ctr = loop_ctr + 1
Select Case loop_ctr
Case 1
[dao_confirm_rs]![BreakOutEventName1] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc1] = [dao_get_event_rs]![EventDescription]
Case 2
[dao_confirm_rs]![BreakOutEventName2] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc2] = [dao_get_event_rs]![EventDescription]
Case 3
[dao_confirm_rs]![BreakOutEventName3] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc3] = [dao_get_event_rs]![EventDescription]
Case 4
[dao_confirm_rs]![BreakOutEventName4] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc4] = [dao_get_event_rs]![EventDescription]
Case 5
[dao_confirm_rs]![BreakOutEventName5] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc5] = [dao_get_event_rs]![EventDescription]
Case 6
[dao_confirm_rs]![BreakOutEventName6] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc6] = [dao_get_event_rs]![EventDescription]
Case 7
[dao_confirm_rs]![BreakOutEventName7] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc7] = [dao_get_event_rs]![EventDescription]
Case 8
[dao_confirm_rs]![BreakOutEventName8] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc8] = [dao_get_event_rs]![EventDescription]
Case 9
[dao_confirm_rs]![BreakOutEventName9] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc9] = [dao_get_event_rs]![EventDescription]
Case 10
[dao_confirm_rs]![BreakOutEventName10] = [dao_get_event_rs]![EventName]
[dao_confirm_rs]![BreakOutEventDesc10] = [dao_get_event_rs]![EventDescription]
End Select
End If
End If
If [dao_confirm_rs]![HomeAddress] > " " Then
[dao_confirm_rs]![MailingAddress] = [dao_confirm_rs]![HomeAddress]
[dao_confirm_rs]![MailingCity] = [dao_confirm_rs]![HomeCity]
[dao_confirm_rs]![MailingState] = [dao_confirm_rs]![HomeState]
[dao_confirm_rs]![MailingZip] = [dao_confirm_rs]![HomeZip]
Else
[dao_confirm_rs]![MailingAddress] = [dao_confirm_rs]![BusinessAddress]
[dao_confirm_rs]![MailingCity] = [dao_confirm_rs]![BusinessCity]
[dao_confirm_rs]![MailingState] = [dao_confirm_rs]![BusinessState]
[dao_confirm_rs]![MailingZip] = [dao_confirm_rs]![BusinessZip]
End If
dao_get_event_rs.Close
dao_get_event_db.Close
dao_get_event_wk.Close
Set dao_get_event_rs = Nothing
Set dao_get_event_db = Nothing
Set dao_get_event_wk = Nothing
'
End If
dao_get_regis_rs.MoveNext
Loop
End If
dao_get_regis_rs.Close
dao_get_regis_db.Close
dao_get_regis_wk.Close
Set dao_get_regis_rs = Nothing
Set dao_get_regis_db = Nothing
Set dao_get_regis_wk = Nothing
dao_confirm_rs.Update
dao_confirm_rs.MoveNext
Loop
dao_confirm_rs.Close
dao_confirm_db.Close
dao_confirm_wsp.Close
Set dao_confirm_rs = Nothing
Set dao_confirm_db = Nothing
Set dao_confirm_wsp = Nothing
End If
' DoCmd.OpenQuery ("qrySetConfirmations")
strDocumentName = "c:\GoldConfLocal\GoldStandardConfirmation.doc"
Dim objWord As New Word.Application
Dim objDoc As Word.Document
objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strDocumentName)
objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute
Set objWord = Nothing
Set objDoc = Nothing
' End If
End Sub

Help Please
Gilles Lafreniere
Thank you so much!
The original code author fixed the problem for me, but I will read through this and perhaps find it better - and now something I can do myself.
:)
Laura
Aleniko29139
Hi Laura,
I've been through this with mail merge and found much better ways to do it.
I'm going to post and article from the Knowledge base and the rason I'm posting it is that the original article wasn't converted to Vs2005 and I think i copied my updates into this: BEWARE of linewrap syntax errors:
What I did was to goo from Access to XML to RTF. It worked really beautifuly and I'd never consider doing anything in mail merge after doing this.
How to use ASP.NET or Visual Basic .NET to transform XML to Rich Text Format for Microsoft Word 2002
Rich Text Format is a text-based format that encodes formatted text, document layout, and graphics. It is commonly used with Microsoft Word. Because RTF is text-based, it can be easily generated with code. If you have XML data that you want to display in Word as a catalog/list or mail merge type document, then transforming your XML data into an RTF stream might be an ideal solution for you. And, in fact, if you are developing a solution where you generate documents on a Web server, then generating those documents using a text-based format, such as HTML or RTF, is preferred over using server-side Automation of Word.
This article provides sample code, with step-by-step instructions, to transform XML into RTF for display in Word by using several approaches:
The Rich Text Format Specification
The Rich Text Format (RTF) specification is a public specification to generate RTF-compatible text files. You can use the documentation for the specification at the following Microsoft Developer Network (MSDN) Web site as a resource to help you build your own RTF files. However, the specification is provided "as-is", and no support is provided by Microsoft Technical Support for the specification. Click the following links for the RTF Specifications:Rich Text Format Specification, version 1.7 (http://msdn.microsoft.com/downloads/default.asp URL=/downloads/sample.asp url=/MSDN-FILES/027/001/758/msdncompositedoc.xml)
Transform XML to RTF
You can take valid XML from any source and transform it to RTF. The following procedure illustrates how you can transform custom XML into RTF either saved to a file or copied to the clipboard.< xml version="1.0" encoding="UTF-8" > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>{\rtf1</xsl:text> <xsl:for-each select="Dictionary/Entries/Entry"> <xsl:text>\par\b </xsl:text> <xsl:value-of select="Word"/> <xsl:text>\b0\i </xsl:text> <xsl:if test="Word[@Type='1']">adj.</xsl:if> <xsl:if test="Word[@Type='2']">n.</xsl:if> <xsl:text>\i0\par </xsl:text> <xsl:value-of select="Definition"/> <xsl:text>\par</xsl:text> </xsl:for-each> <xsl:text>}</xsl:text> </xsl:template> </xsl:stylesheet>Transform a DataSet Into RTF
Visual Basic .NET allows to you to easily do transformations on datasets. This procedure shows you how you can take related data from the sample Northwind database and transform it to RTF. Two different transformations are demonstrated: a simple RTF document that lists Customer contact information and a somewhat more complex RTF document that displays order information for customers in a mail merge-type format.WebForm1 is created for you.
Button1.Text = "View Contact Information" Button2.Text = "View Customer Orders"NOTE: The following code assumes you have SQL Server installed on the localhost. If you have to use another computer, change the Data Source member of the connection string accordingly.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" > <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>{\rtf1</xsl:text> <xsl:text>{\fonttbl{\f0\froman\fcharset0\fprq2 Times New Roman;}{\f1\fswiss\fcharset0\fprq2 Arial;}}</xsl:text> <xsl:text>{\header\pard\fs50 My Customer Contacts}</xsl:text> <xsl:text>{\footer\pard\fs18 Page {\field{\*\fldinst PAGE}</xsl:text> <xsl:text>{\fldrslt }} of {\field{\*\fldinst NUMPAGES}{\fldrslt 1}} \par}</xsl:text> <xsl:text>\f1\fs20</xsl:text> <xsl:for-each select="Contacts/Customers"> <xsl:text>\par\b </xsl:text><xsl:value-of select="CustomerID"/><xsl:text>\b0</xsl:text> <xsl:text>\par </xsl:text><xsl:value-of select="CompanyName"/> <xsl:text>\par </xsl:text><xsl:value-of select="ContactName"/> <xsl:text>\par </xsl:text><xsl:value-of select="Phone"/> <xsl:text>\par</xsl:text> </xsl:for-each> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="Customers"> <xsl:text>\par\b </xsl:text><xsl:value-of select="CustomerID"/><xsl:text>\b0</xsl:text> <xsl:text>\par </xsl:text><xsl:value-of select="CompanyName"/> <xsl:text>\par </xsl:text><xsl:value-of select="ContactName"/> <xsl:text>\par </xsl:text><xsl:value-of select="Phone"/> <xsl:text>\par</xsl:text> </xsl:template> </xsl:stylesheet>