Modules & VBA :: Word Document Load When User Click Button And Perform Email Merge
Oct 7, 2013
I have a Word 2010 document linked to an Access 2010 data source. When a user clicks a button in Access, the Word document loads and performs a email merge using the below VBA code:
Private Sub Document_Open()
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
[Code] ....
However, as the .mailsubject part is not in the loop it is only retrieving the first Return Code. I have tried to integrate in the loop to no avail. Also, how do I add static text to the Subject, I need something like "Your Return Code" + "Return Code"..
I'm using ACCESS 2010. I have a form which is having a embedded word document. What I'm trying to do is i want to enable user to format a mail in the embedded word document which will contain rich text and screenshots then with a click of button an outlook mail should open and content of this document should be pasted there. Once user sends this email, I want to save content of embedded document in the database.
I have created a button that works fine however it will only work one click per form load and i cant seem to figure out why.
Code: Private Sub BntExpired_Click() Dim QryAllCourses As recordset Do Until ExpiryDate > Date Or ExpiryDate = "" MsgBox ([FirstName].Value + " " + [SecondName].Value + "'s course in " + [CourseName].Value + " has expired") recordset.MoveNext Loop Exit_BntExpired_Click: Exit Sub Err_BntExpired_Click: MsgBox Err.Description Resume Exit_BntExpired_Click End Sub
I have a template letter in Word that I want to import into Access, so when I choose from a combo box an employee's ID, it automatically displays a report using the Word document template and filled with all related information of that employee (name, nationality, etc.) + it shows today's date. Then I can Save&Email to an Outlook contact.
I am trying to query my records by the current records selected date then send the results in the body of an email on click. I believe I am close but I think there is a problem with the date format because I am getting 3421 Data type conversion error. Here is what I have:
Code:
Private Sub eMail_Click() On Error GoTo EH Dim dbExceptions As Database Dim rstExceptions As Recordset Dim dbDate As Database Dim rstDate As Recordset
In access database, Is there anyone know how use macro to open a word document on a share drive..(example S:safetyRegulation.doc)?.
Here is what I did and it doesn't work.. Runapp command line: C:Program FilesMicrosoftOfficeOfficeWINWORD.EXE //S:safetyRegulation.doc. Is there any easier way to do this? Please advice..thanks Rob..
Sorry if this isn't the right place for this, but it didn't seem to fit in anywhere else.
I have a simple database, which pretty much now works as I want it to. The only element I really needs to get working is some way of producing - at the click of a button - a Microsoft Word document, elements of which are populated by fields on whichever record the database user happens to be viewing at the time.
I already have the exact layout and template of the Word document I want, but I need to be able to view any record then click one button to fill that template with the record's fields and print it, and another button to fill the template with the record's fields and save it (again, in .doc format).
I have a form with various details on clients. I have 6 different letters that need to pull off different fields from the client form. Is it possible to have a button (for each letter) that when when clicked will open up the word document for the specific client with the fields on their poulated, such as name, ammount owed etc.
Mail merge does not do the trick as it brings back all the clients in the database and not the specific one.
I have documents (mostly Word) stored in an Access table. The table contains two fields. (1) a text field with the document's name and (2) an OLE field that holds the document.
When I press a button with the document's name on it (or it could be a hyperlink or a dropdown) on a form then I would like the document stored in the matching OLE field to open in the appropriate program for that document.
If I could set the permissions of the document to read-only then that would be great too. If I could prompt for read-only or read-write (no password necessary) access upon opening then that would be even better.
I can store documents in the table, but I have no idea how to launch them from a form button (or hyperlink, or dropdown).
Note: This is all within Access. This is not a web page related question.
I am creating a database. I have all my forms, queries, tables, reports just as I need them. However, I would like to have a command button on my switchboard that will pull from a query to feed to a Word document (that's actually a letter on my company letterhead). I know a Macro has to be involved with this, but again, I have little to no knowledge of Macros. Also, I would like to be prompted to enter a client ID number when I click on this command button (because I only want to print a letter for a new client, not all of them).
I would like to open a Word document using a button control on a form to a file path listed in a field on the form. I use the following code when I want to open a single specific document...
Dim wdApp As Word.Application, wdDoc As Word.Document On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then 'Word isn't already running Set wdApp = CreateObject("Word.Application") End If On Error GoTo 0 Set wdDoc = wdApp.Documents.Open(File path here) wdApp.Visible = True
...but in this case the file path I want to use will be designated by a field on the form. I know I could just use a hyperlink but I don't like the way it looks on the form. I would rather hide that field and have code pull that path when I hit the button.
So how would I change my code to make it so the value in the file path field on the form goes in where it says "File path here" in my code above?
I have an access form that fills an access table (MS Access 2003). Also, I have a Word (2010) document/template with some template text and empty fields which should be filled with data from access. Is it possible to insert a button in access form which would open a word document and populate appropriate fields with data from that form?
I have been trying to populate a merge document from access. I have the dotx files organised and the recipient file (Query) within my main access project. The following code opens word, opens the selected file (dotx) but can't find the db file.
I am using access 2010 and .accdb database format. I have temporarily put in MsgBox lines to display the running content of fields and they are producing the right info.
Private Sub DocumentsCbo_Click() ' load precedent template as a dotx, merge fields into precedent document, allow user to modify if needed, save it as a pdf On Error GoTo ErrTrap Dim MyPath As String ' Path of the source template Dim DestPath As String ' Path of destination document
a) Open a word document from MS access / VBA, b) Connect to data from a query c) mailmerge it d) Save it as a new document containing mailemerged letters.
The code does open the required document as I can see it open.
I put a message box to recheck that filename/path is what I mean, and to to know till which line the code runs. Code runs till that point and that word doc is seen open. I get the error message before
Then I get error message.
I was fooling around and was getting message " This command is not available because no document is open" I tried to remove few lines thinking redundancy. Before getting the message, I was also getting the error trapping message "No documents opened."
Now I am getting different message.
I am getting message " The remote Server Machine does not Exist or is unavailable"
Following is the code I have written.
Dim xlApp As Object Set xlApp = CreateObject("word.Application")
We need to replicate an Access report we have in Microsoft Word. The report has a fixed, small image in the header and so we embedded it in the report (it is not in an external file). To put this image in the Word document the only way we have come up with is shown in the code below.
Code: Dim apWord As Word.Application Dim doc As Word.Document Set apWord = CreateObject("Word.application") doc.Shapes.AddPicture "G:ImagesSinful Banner.bmp", False, True, 0, 0, 540, 42
Which requires an external image file. We really would like to avoid this. We could make a template Word document, but that too would be an external file. We know how to put this image in a table as an OLE object, but can't find any way to get it from the table into the Word document.
Not sure if this is possible but I am trying to extract data from a word document to set up a database.
Basically I am trying to capture data from completed forms, similar to the sample attached, the actual blank form is 20 pages long and once completed can be as many as 30 pages, or even more, although the format doesnt change (i.e. individidual cells will expand to fit the data in the cell).
I want to be able to scan through the completed forms and extract the data i.e. Full Study Title, Short Study Title, Study Type etc. into a database.
The issues: 1. Each document will have a different name but will be stored in the same location. 2. What is on page 8, for example, in one document is not necessarity going to be the same on every document (due to expanding cells) 3. Each sector is in a separate table but tables can spread across several pages. 4. Some data is stored in a checkbox format rather than text. 5. I dont want to extract all of the data, only certain sections (at least at this stage).
If I use the word template named "ABC.dot" as attached and write the following piece of code to print off the letters with different appropriate background , it works perfectly fine:
Code: Sub PrintLetters() Application.DisplayAlerts = False Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim r As Long Set cn = New ADODB.Connection
[Code] ....
But if I combine two templates together in one template as attached "Capita.dot" then it doesn't display background picture at all in any of the cases. I am using the same piece of code but the background image is not displaying. The background image shows logos for each letter like For capita letters , the logo will be capita . For Friends Life letters the logo background will be different.
I was tasked to create an application where by the user enters keywords into an Access form, and when he clicks the button, it will run the keywords against the file names stored in the table and automatically open the Word document that is the best match.
I have created a table query called Directory, which contains FPath (Z:), FName (Document1.doc) and Directory (Z:Document1.doc).
Code: Private Sub Command2_Click() Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim filepath As String Dim strSearch As String
If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
[Code] ....
This is the code that I am currently using to search and open the Word documents, however, this code only manages to open Microsoft Word program without loading any documents. Also, there are no error messages when I click the submit button.
There are two pages in a word document. All the pages have same headers as attached in word document "Capita.doc". I want to display that header on just first page and on second one page, I want to display watermark stored in "J:PAP107.jpg". The following code displays same watermark on all the pages i.e "J:PAP107.jpg" but I want to keep the header as in the attached word document on first page only and display watermark stored in "J:PAP107.jpg" on second page.
Code:
Private Sub CmdPrint_Click() Call WordSetupQA("C:CAPITA.dot", "J:PAP107.jpg", Format(DateSerial(ComboBox4, ComboBox3, ComboBox2), "mm/dd/yyyy"), pno) End Sub
Code: Sub WordSetupQA(fnTemplate As String, fnBackGroundPic As String, b As Date, a As String) On Error Resume Next 'MsgBox txtbox Application.DisplayAlerts = False Dim strworkbookname As String strworkbookname = "C:System1.mdb" Set WordApp = GetObject(, "Word.Application")
I am trying to export an attachment item (Picture .jpg) to a word document. I have been exporting text to a word document successfully with below syntax "
With rst strLandSalesID = Nz(.Fields("LandSalesID")) strPhotograph = Nz(.Fields("Attachments"))
I am having the strangest results with my automated mailmerge. Basically it does work, but not all the time. The basic idea is to allow the user to dynamically create a query that produces a result list which fills a temporary table. The use then selects a prebuilt merge template and merge is executed against the temp table. The merge template are of the .doc type, but sme have been converted to .docx; the .doc files tend to work most often, but all of the will eventually get a Table is locked message... However if I run in test mode with code breaks and manually step through the process it always works... here is the heart of the code ...
Err_Pos = 10
Code: DoCmd.SetWarnings False ' if tmp tbl left over from last run kill it DoCmd.RunSQL "Drop table Word_Merge_Tmp_TBL" Err_Pos = 12
[Code].....
There are many error cases in the error catch routine. That I have managed to make Access stop hanging when word has a problem or the table is locked. But I can't get the table to be free consistantly and why does it always work when I manually step through the code.
copying all the contents/text from word document and pasted that in the Memo Field, I have a Recruitment database where I have 02 fields on is CV Path (Text Field) that stores the CV Path (Word Document Path) and another text box content (Memo Field) where I would like to copy all the data from the word document to the Content text box (Memo) field.
I have put a Command button on the form...the code to "Copy the content/text" from [CV Path] word document and add it to the "Memo" field.
I'm trying to work out how to attach a word doc to the attachment field of a table when I add a new Record. The following code work's fine if I add it to the On Load Event on the Form, but the doc is attach'd to the first record. When I add the code to the Add New Record button, I get the error msg: "File already part of the Multi-Valued Field" and nothing in the attachment field.
Code: Private Sub Add_Record_Click() DoCmd.GoToRecord , , acNewRec Me.Description.SetFocus On Error GoTo Err_AddImage Dim db As DAO.Database Dim rsParent As DAO.Recordset2 Dim rsChild As DAO.Recordset2