Results 1 to 4 of 4
  1. #1
    nt100 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    5

    Query With Join For VBA Mail Merge, Access 2016


    I developed an application as attached with MS ACCESS VBA to do mailmerge word documents with the following queries (qryTReapptNomination_HCAP) and (qryTNewNomination_HCAP) separately

    I run frmReport
    Re-appointment - > Honorary Clinical Assistant Professor
    It works fine with qryTReapptNomination_HCAP

    Its query structure is shown bleow
    SELECT tblProcessTReAppt.TRef, tblTutor.UID, tblTutor.Title, tblTutor.LastName, tblTutor.FirstName, tblTutor.Alias, tblTutor.ClinicAdd1, tblTutor.ClinicAdd2, tblTutor.ClinicAdd3, tblTRank.HDesc, tblTAppt.JobPosition, tblTAppt.Company, tblTAppt.Honorarium, tblTAppt.Allowance, tblTAppt.FCF_No, tblTAppt.budget
    FROM ((tblProcessTReAppt LEFT JOIN tblTutor ON tblProcessTReAppt.TRef = tblTutor.TRef) LEFT JOIN tblTAppt ON tblProcessTReAppt.TRef = tblTAppt.TRef) LEFT JOIN tblTRank ON tblTAppt.RankCode = tblTRank.ID
    WHERE (tblTAppt.AppointedBy = "UG") and (tblTAppt.RankCode=1) and (tblProcessTReappt.ReplyToInvitation= "Y")
    ORDER BY tblTutor.LastName, tblTutor.FirstName, tblTutor.Alias;

    However, when I run frmReport
    New Appointment - > Honorary Clinical Assistant Professor
    pops up of “Confirm Data Source” and then runs into error "5922: Word was unable to open the data source".

    qryTNewNomination_HCAP
    SELECT PT.TRef, PT.ApptDtStart, PT.ApptDtEnd, T.UID, T.Title, T.LastName, T.FirstName, T.Alias, T.EMail_1, T.BQual, T.PQual1, T.PQual2, T.PQual3, T.ClinicAdd1, T.ClinicAdd2, T.ClinicAdd3, TR.HDesc, NA.JobPosition, NA.Company, NA.Honorarium, NA.Allowance, NA.FCF_No, NA.budget
    FROM ((tblProcessTNewAppt AS PT INNER JOIN tblTutor AS T ON PT.TRef = T.TRef) INNER JOIN tblTNewAppt AS NA ON PT.TRef = NA.TRef) INNER JOIN tblTRank AS TR ON NA.RankCode = TR.ID
    WHERE (PT.ReplyToInvitation= "Y") AND (NA.RankCode = 1)
    ORDER BY T.LastName, T.FirstName, T.Alias;


    The queries work from MS Word mail merge utilities directly.

    I have inspected several times and found nothing wrong with the structures and queries. It's weird that one query works fine but a similiar query doesn't work for the same VBA codes.

    Pls. find the attached application for details and tests.

    Thank you in advance for any idea on this problem.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    I have to ask why are you bothering with mail merge instead of just using Access report?

    First thing I did with your code is run Debug > Compile. It errors on a reference to fraNewApptLetDelivery.

    Why do you have code for buttons that don't exist?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nt100 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    5

    Red face

    I am sorry for removing some controls that I thought is not relevant my question. Since my application is very big. I just wanted to simplify the matter. Now, the latest app (Appt_1.zip) Appt_1.zipas attached has that you wanted

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    When the mail merge initiates and tries to OpenDataSource, I get a popup "Appointment.accdb is locked for editing by 'another user'." I select 'Open read-only copy'. The Word template opens but get another popup "Header Record Delimiters". I cancel that popup and now I get the 5922 error Unable to open the data source.


    Again, why do you want to endure this torture?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Mail Merge from Access
    By mbelc in forum Access
    Replies: 3
    Last Post: 11-08-2016, 11:44 AM
  2. Replies: 0
    Last Post: 07-27-2016, 11:21 AM
  3. Replies: 2
    Last Post: 08-13-2015, 11:20 AM
  4. Mail Merge from Access Query
    By Baldeagle in forum Reports
    Replies: 5
    Last Post: 03-17-2012, 06:43 PM
  5. Access Query mail merge to Word
    By Jan Collier in forum Access
    Replies: 8
    Last Post: 08-30-2010, 09:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums