Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9

    The Database Has Been Placed In A State By User ‘Admin’ on Machine….

    Hi everyone.

    We just switched from Access 2016 to Access 365. My database is now giving this error when I try to do a mailmerge: "The database has been placed in a state by user ‘Admin’ on machine ... that prevents it from being opened or locked."



    There is no one else using this database and there is no lock file showing. Do I need to change the connections now that it is using 365? Could that be causing the issue?

    This is what I currently have (and where the error is occurring):

    Code:
           docLetters.MailMerge.OpenDataSource Name:=CurrentDb.Name, LinkToSource:=True, _
                      Connection:="TABLE tblAuthorizerLetterFinal", SQLStatement:="SELECT * FROM [tblAuthorizerLetterFinal]"
    Code has these statements at the beginning:
    Dim db As DAO.Database
    Set db = CurrentDb
    Code has these statements at the end:
    db.Close
    Set db = Nothing

    I have been struggling trying to fix this for a while so any help you can give is very much appreciated!

    Karin

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Do you have the db open? If so, close it, then run mailmerge (from word)
    you dont need the DBO code to run a mail merge.

  3. #3
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9
    Hi.
    Thank you for the reply.
    There is a button on my form which will allow the user to do the mailmerge and it will also update a whole bunch of fields in the database.
    This code was working in Access 2016. Not sure what changed in Access 365 to break it.
    Karin

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I would suggest you modify the code you use to replace the mail merge record source with a text file. I use a modified version of Albert's easy mail merge https://hitechcoach.com/downloads-ma...asy-word-merge but basically all you need is to export a query or a temp table (your tblAuthorizerLetterFinal) as text using Docmd.TransferText then pass the name of the file to the mailmerge line:
    Code:
    .MailMerge.OpenDataSource Name:= strMailMergeFileName, ConfirmConversions:=False, ReadOnly:= _
            False, LinkToSource:=True, Revert:=True, AddToRecentFiles:=False
      'where strMailMergeFileName is a string variable holding the newly created text file
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9
    Thank you Vlad. That is getting me closer. It is no longer crashing, but the mailmerge output has no data, only field names. I am assuming I am doing the DoCmd.TransferText incorrectly. This is what I am using:

    DoCmd.TransferText acExportMerge, , "tblAuthorizerLetterFinal", strMailMergeFileName

  6. #6
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    You might want to consider this:
    I decided to discontinue the use of MailMerge for generating doc and docx files due to various reasons. Instead, I found out that implementing a custom function, which opens word documents, creating a copy of the file and facilitating value replacement in the copy, proved to be significantly more reliable.

    It was also remarkably easier for my users to design their own doc and docx templates, because they just had to use some placeholders in the places where the values were to be put, instead of all that MailMerge configuration, constant undocumented issues and weird behaviors happening randomly for no apparent reason. It was much better to let the user create their own doc/docx file and just add their placeholders. It also stopped being necessary for me to intervene whenever a new template was created or modified. I could provide example code if you want to do it that way.

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,653
    Like Vlad, I've used Albert Kallal's super easy word merge for 10+ years. I've made some modifications to my own liking and it's always worked flawlessly. Highly recommend it, even if only to read through his code to see how things work.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @Karin: don't use acExportMerge as the parameter, just use acExportDelim (for a comma delimited csv file); I always used saved specifications in case some fields needed to be "tweaked".

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9
    I looked at Albert Kallal's word merge and it needs code change to work on a 64 bit system. I don't know how to do that.

    I would like to get Vlad's export to text working, as that seems the simplest solution.

    I did a manual export to text of the table with the data and saved the export specification - I presume it is saved in Access somewhere? I called it "Export Specification".

    When I run my program I am getting a pop up asking about Header Record Delimiters. It is using tab as the field delimiter and enter as the record delimiter.

    Click image for larger version. 

Name:	Header Record Delimiters.PNG 
Views:	33 
Size:	7.4 KB 
ID:	50291

    When I click OK I get run time error 5922: Word was unable to to open the datasource. I checked the datasource and there is data in it.

    Can anyone tell me what I am doing wrong? Here is my code:

    Code:
            strMailMergeFileName = "M:\AADL\Authorizer\Authorizer Database TEST\Exports\MailMerge\temp.txt"
    
            DoCmd.TransferText acExportDelim, "Export Specification", "tblAuthorizerLetterFinal", strMailMergeFileName, False
            
            Set appWord = CreateObject("Word.Application")
    
            Set docLetters = appWord.Documents.Open("M:\AADL\Authorizer\Authorizer Database TEST\Letter Templates\Authorizer - Approved.docx")
    
             ' execute mailmerge
             docLetters.MailMerge.OpenDataSource Name:=strMailMergeFileName, _
                      ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, Revert:=True, AddToRecentFiles:=False
    Thanks for your help!
    Karin

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi Karin,
    Would you be able to upload a sample of your db that includes the tblAuthorizerLetterFinal table (no sensitive data, just one or two dummy records) and a copy of the Word template)?
    I would suggest you try a CSV delimited export first; I think what you need is to set the last parameter in the TransferText to True (HasFieldNames), so please try this:
    Code:
    
    strMailMergeFileName = "M:\AADL\Authorizer\Authorizer Database TEST\Exports\MailMerge\temp.txt"
    
    
    'DoCmd.TransferText acExportDelim, "Export Specification", "tblAuthorizerLetterFinal", strMailMergeFileName, False
     
    DoCmd.TransferText acExportDelim, , "tblAuthorizerLetterFinal", strMailMergeFileName, True
     
    Set appWord = CreateObject("Word.Application")
    
    
    Set docLetters = appWord.Documents.Open("M:\AADL\Authorizer\Authorizer Database TEST\Letter Templates\Authorizer - Approved.docx")
    
    
    ' execute mailmerge
    docLetters.MailMerge.OpenDataSource Name:=strMailMergeFileName, _
                      ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, Revert:=True, AddToRecentFiles:=False
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9
    Vlad, I tried doing the changes you suggested and I am still getting errors.
    I have tried to attach a small version of my database and the Word document.
    Authorizer Database TEST.zip Authorizer - Approved TEST.zip

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I'll have a look shortly, but the Word template is missing from the attachment.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Also, as the file you uploaded seems like a regular front-end linked to your back-end I cannot see the tblAuthorizerLetterFinal table, would you please include that (just one or two dummy records so I could test the Word doc against the export)?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,653
    I looked at Albert Kallal's word merge and it needs code change to work on a 64 bit system. I don't know how to do that.
    To be honest I didn't know how either but I just figured it out (I think). I tested it in 64 bit and it works. yea me.

    Replace this block of code:
    Code:
    Private Declare  Function GetTempPath Lib "kernel32" _
    Alias "GetTempPathA" (ByVal nBufferLength As Long, _
    ByVal lpBuffer As String) As Long
    With this block of code:
    Code:
    Private Declare PtrSafe Function GetTempPath Lib "kernel32" _
    Alias "GetTempPathA" (ByVal nBufferLength As LongPtr, _
    ByVal lpBuffer As String) As Long
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  15. #15
    KarinG is offline Novice
    Windows 10 Office 365
    Join Date
    May 2023
    Posts
    9
    I forgot to upload the backend! Sorry! Here it is:
    Authorizer Database_be-TEST.zip

    The Word template is there, were you able to see it? Or do you want me to upload it again?

    moke123 - Thanks!

    Karin

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-03-2021, 01:27 PM
  2. Replies: 5
    Last Post: 02-01-2021, 08:52 AM
  3. Replies: 3
    Last Post: 08-26-2015, 09:46 AM
  4. Replies: 1
    Last Post: 07-20-2012, 05:35 PM
  5. Replies: 1
    Last Post: 08-25-2011, 11:41 AM

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