i have a stores database for all items in a warehouse. i need to be able to have a button on my form that sends the current record to a word template to be printed out on labels. i need to be able to specify the amount of labels for each record, and i need to be able to send multiple records to the same template. i have absolutely no idea how to do this.
ive got the template set up, but currently it is mailmerged the normal way, meaning it would just print every record in the DB on the labels. i was thinking of having some kind of check box in the DB so that the user can use the form to find all the records they want to print, check the box for each (and also enter a number for the amount of times they want that record printing on the sheet) and then have a button to send the final document to the printer. this brings up another issue - how do i empty the check box for every record each time the form is used so that all the previously printed records do not get reprinted?
If anyone has got any idea how to overcome any of these problems i would be extremely grateful.
I have started having problems with MailMerge in my database - it has worked before but now I get this error:
Runtime error 5922
"Word was unable to open data source"
Here is my code:
Function MailMerge(strMMTemplate As String) Dim objWord As Word.Application Dim objDoc As Word.Document
Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Open(fldMailmerge & strMMTemplate)
'Make Word visible. objWord.Application.Visible = True 'Set the mail merge data source objDoc.MailMerge.OpenDataSource Name:="C:cmoscmos.mdb", LinkToSource:=True, Connection:="TABLE tblMailMerge_Temp_Full", SQLStatement:="SELECT * FROM tblMailMerge_Temp_Full" 'Execute the mail merge. objDoc.MailMerge.Execute objDoc.Close
Set objWord = Nothing Set objDoc = Nothing End Function
I have searched high an low through the forum and web - but no luck.
I am trying to perform a mail merge from Access database table and using Word letter setup with all the necessary variables. I am using VBA in access to perform this task. All works ok to the point but the first snag I had when the Access was not open in Read-Only mode and where 'OpenDataSource' statement was refusing to merge the database to the letter I managed to overcome this by opening Access in Read-Only mode.
However I hit the second snag.
When running 'OpenDataSource' statement the pop up box comes with option to select a table I want to make connection too.
The table is listed in the within the parameters for the statement, so it does not make sense why is this question.
This is my code:-
Dim WordApp As Word.Application Set WordApp = CreateObject("Word.Application") MergePATH = Application.CurrentProject.Path & "" With WordApp .DisplayAlerts = wdAlertsNone .Visible = False .Documents.Open (MergePATH & "MTSheet3.DOC") With WordApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute End With .ActiveDocument.SaveAs (MergePATH & "Dummy.doc") .ActiveDocument.Saved = True .ActiveDocument.Close .Quit End With
Set WordApp = Nothing
Can anyone explain what the problem ?
Thanks The is holding up progress of a big project
I am using Access 2003 and have secured my database, so that it now consists of an .mdb and an .mdw file. The .mdb is opened using the security settings in .mdw using a shortcut.
I want to set up a mail merge into Word 2003, but whenever I try selecting my database as the source of the data I want to merge, it won't let me log in.
Can anyone advise me how I can get this to work correctly?
This mailmerge document draws its personal information from a query in my database. And sends off personal emails to a number of donors.
I want to attach a personal document called 'Allocations.docx' which is also a mailmerge document drawing its personal information from the same query. How can I automate the attachment of this document to the email so that each donor gets their own email plus their own attachment?
Can something be added to the existing line of VB which will do what I want? If so, what do I need to add?
I just started having an issue with a mailmerge launching form in Access. A button I've set up, called "Order Form," uses the following code to launch Word, merge the data into the document, save the document, and close out the template. It's a large sample, and I think it may have come from this website at some point last year:
<---------START--------->
Private Sub OrderForm_Click() 'creates an SQL statement to be used in a query def 'On Error GoTo ErrorHandler
Dim val As String Dim db As Database Dim rec As DAO.Recordset Dim strSQL As String Dim strDocumentName As String 'name of the template document
Set db = CurrentDb Set rec = db.OpenRecordset("SELECT Order_ID FROM tmpCurrentTGOrderID;")
While Not rec.EOF val = rec("Order_ID") rec.MoveNext Wend
rec.Close
'Select all records from the record table were the table's Order_ID field matches 'that of the temporary table's. 'qry = "SELECT TG_Orders.Order_ID, TG_Orders.Order_Date, TG_Orders.Order_HonoredPerson, TG_Orders.Order_TreeGiver, TG_Orders.Order_PlantingState, TG_Orders.Order_Product, TG_Orders.Order_Type, TG_Orders.Order_Line1, TG_Orders.Order_Line2, TG_Orders.Order_Card, TG_Orders.Order_Occasion, TG_Orders.Order_First, TG_Orders.Order_Middle, TG_Orders.Order_Last, TG_Orders.Order_Have, TG_Orders.Order_Digits, TG_Orders.Order_CardType, TG_Orders.Order_Comments, TG_Orders.Order_Donate, TG_Customers.*, TG_Shipping.* FROM (TG_Customers INNER JOIN TG_Orders ON TG_Customers.Customer_ID = TG_Orders.Customer_ID) INNER JOIN TG_Shipping ON TG_Orders.Order_ID = TG_Shipping.Order_ID;"
Call SetQuery("TG_OrderFormQuery", strSQL) Dim strNewName As String 'name to save merged document as strNewName = "Order " & Format(CStr(Date), "MMM dd yyyy") Call OpenMergedDoc(strDocumentName, strSQL, strNewName)
Exit Sub ErrorHandler: MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error" Exit Sub
End Sub
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 OpenMergedDoc(strDocName As String, strSQL As String, strReportType 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 this database, merges the template, 'saves the merged file with a descriptive name, then closes the merge template
'Set the directory for any labels generated Const strDir As String = "D:LOA-DataMerge Templates" 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 'merge to a new document 'if you are not sure of the SQLStatement to use in your OpenDataSource string, uncomment the following four lines to have the 'current SQLstatement print in the immediate window. You can then copy the returned string to your code 'Debug.Print objWord.Application.ActiveDocument.MailMerge.DataS ource.QueryString 'objWord.Quit 'Set objWord = Nothing 'Exit Sub
objDoc.MailMerge.OpenDataSource _ name:="D:LOA-DataLOAv817.mdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="QUERY TG_OrderFormQuery", _ SQLStatement:="SELECT * FROM `TG_OrderFormQuery`" 'notice that this is not the SQL statement that makes up the QueryDef of the query. It 'is the SQL statement that tells Word whether to use all the records returned by the 'Query. Notice also the funky single quotes – this is what DataSource.QueryString returned 'to me in the immediate window. I’ve also seen the query name written in 'brackets [ ], 'but have never tested this code with them.
objDoc.MailMerge.Destination = wdSendToNewDocument objDoc.MailMerge.Execute 'save the merged document with a descriptive name 'you can delete this line if you want to leave the document with the default name “Labels 1” or “Letters 1” objWord.Application.Documents(1).SaveAs (strDir & "" & strReportType & ".doc") 'close the merge template objWord.Application.Documents(2).Close wdDoNotSaveChanges '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
<---------END--------->
Just today, this code started auto-minimizing the MS Word window, causing user error (after the documents been minimized, instead of clicking on the task bar, the user would click the button again, prompting that the document is already in use, would you like to save changes before closing the document, etc). Is there anything in this code that is telling Word to minimize? It's only happening on this one button, and there are 7 other mailmerge buttons on the same form, using the same code, that work fine.
I am trying to generate letters from ACC2003 db into Word2003. Reason for Word is so client can edit letters if required. I have set up a maketable query to generate a temporary table in the Db and the mailmerge master document all formatted and pointed at the temporary table. I still need to get the automation running so that the letters merge and print on a command button. My immediate issue is that the address lines are intentionally spread across 5 fields Addr1, Addr2, Addr3, Town, Postcode. Not all fields in every record are full, and with the query it would be impossible to eliminate fields on the chance they might be empty. As a result my mailmerge has blank address lines which do not look professional. Can anyone point me to how I might solve this given my proposed use - if it was a report then I have a little code module that neatly eliminates blank lines but I cannot see how I could integrate this into the mailmerge process. Thanks for any help or pointers
I have an issue which having read some previous threads may not be resolved simply. My database is password protected.
The password (presumably) is preventing the mailmerge from connecting the deata with the template. There is not even a password request shown. Is there any way that this can be overcome. There are a number of mailmerges but all are pulled from the same data query, can i unprotect this query only??
After convincing my boss that the dbase can easily run securely, your help will be very much appreciated.
I have a database of film events, for which i have to do posters.
With the click of a button on a form, access opens word and puts all the fields in, including a field called [photo], which is the name of the image stored outside of the database.
Is there a way of getting that image into the word Document with all the other fields? Or have I just wasted an afternoon....
I'm looking to add a button to my Customers form which will mailmerge the current record to a Word template and then save the Word doc as a new file (Ideally the customer's name).
I've looked at the Super Easy Mailmerge but I can't work out how to implement it without all of the variables (selecting documents etc.).
The files will all be saved to one location (C:CustomersExports) and this won't change.
This is also the location of the mailmerge template (C:CustomersExportsTemplate.docx)
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.
In an Access 2010 form is it possible to export select records and fields in those records to a specific location?
Code: Set objDialog = Application.FileDialog(4) With objDialog .AllowMultiSelect = False .Title = "Please select a File" .InitialFilename = "C:" .Show If .SelectedItems.Count = 0 Then MsgBox ("Action Cancelled") Else
[code]....
The user can select the directory using the code above, but can specific fields in records be exported to a excel workbook in that selected directory?For example, if the are 5 records in the database can the fields LastName,FirstName,BirthDate in records 1,2,3 be exported to Setup.xlsx in that selected directory?
I have a table (tbl Team Info) which contains names and codes for teams within my business (>400 records) and another table (tbl Process) which contains a list of high level tasks (30 records).
I need to create something where for each team name 9in tbl Team Info) I can map them to the tasks that they undertake (in tbl Process) and assign a percentage of time then spend on each task. Each team could map to several different tasks.
In my simple database (attached), I need to mass duplicate Tasks and their Notes.
I have three tables: tbTasks (PK: Task_ID), tbNotes (PK: Note_ID), jtbTaskNotes (FKs: Task_ID and Note_ID). jtbTaskNotes is my many-to-many junction table that ties Tasks to Notes.
The main form (fmTasks), bound to tbTasks, has a subform (sbfm_TaskNotes) that displays notes associated with each Task. On themain form,you select which Tasks you want duplicated via a checkbox. The append query (quCopyTasks) will duplicate all tasks that have the checkbox checked. All good there. However, I can't figure out how to also duplicate each task's Notes.
I found Allen Browne's solution [URL] ....., but that only handles duplication of one record at a time, whereas I need to duplicate many records at a time (sometimes 10+ records). How do I go about duplicating multiple Tasks and their associated Notes?
Before you ask "why are you duplicating records?": There are times when tasks need to be re-accomplished and therefore need to have a new record. It's easier to duplicate records than it is to hand-jam everything again.
One shows my form with the Transporters Subform with 3 entries, and 1 entry.The three line items that say "Transporter" are in one subform. I used this code
Code: Private Sub Form_Current() If Me.RecordsetClone.RecordCount >= 3 Then Me.AllowAdditions = False End If End Sub
to limit the number of records I can add to 3 or less.My issue is that I lost the blank text box that allows you to add another record. So, if I only have one Transporter listed, there's no box to let me add a second or third.I have the following properties for the Transporters Subform set to "Yes":
Data Entry Allow Additions Allow Deletions Allow Edits Allow Filters
I have built a qry that initially shows the correct information. For example.
tblContent has 289 records with a Type = Class.
I built a Query to select from tblContent Type = Class and I get 289 records. I add additional criteria of Progress <>"Not Scheduled", I then get 206 records. I then add additional criteria Last Name <>"Demo" And <>"Care" And <>"Support". This brings up 200 records, but the query appears to duplicate each record 3 times. I do not have 3 of the same types of records.
The SQL Statement is below
SELECT tblProfile.LoginName, tblProfile.FirstName, tblProfile.LastName, tblProfile.Organization, tblProfile.CostCenter, tblContent.Title, tblContent.Type, tblContent.Code, tblContent.[Date Assigned], tblContent.[Date Started], tblContent.[Last Accessed], tblContent.Progress, tblContent.[Date Completed] FROM tblProfile INNER JOIN tblContent ON tblProfile.LoginName = tblContent.LoginName WHERE (((tblProfile.LastName)<>"Demo" And (tblProfile.LastName)<>"Care" And (tblProfile.LastName)<>"Support") AND ((tblContent.Type)="Class") AND ((tblContent.Progress)<>"Not Scheduled"));
The qry is named qryPhysical Class. I have provided the link to view the database. Can you help me?
All seemed to be working well, however, I noticed that all my subtable records in the database are exporting with each Primary table record. In my output, I'm looking to see each primary table record followed by one or more subtable records from a one to many relationship.
(Office 2010) Access/Word
Private Sub cmdPrint1_Click() Dim objWord As Word.Application Dim docm As Word.Document Dim db As DAO.Database Dim rstLandSales As DAO.Recordset
Dim dbs As DAO.Database, sql As String, rCount As Integer Set dbs = CurrentDb sql = "DELETE * dbo_InvPrice Inner Join (dbo_InvPrice Inner Join UpdatedPricing on dbo_InvPrice.StockCode = UpdatedPricing.StockCode ) ON on dbo_INvPrice.PriceCode = UpdatedPricing.PriceCode " dbs.Execute sql, dbFailOnError
I have a form which needs update ever month. When the form is opened, the end user can see the old records and data, and also a new record is added for any new data. I want to protect the old saved data and the user can only add, edit, or delete the new data in the newly added record. The problem is once a user adds the new data and moves to another record or another form, then he/she cannot edit or change the new data in case if there is any mistake or need to change something after couple of minutes.
I changed the Form Data Properties "Allow Additions", "Allow Edits", and "Allow Deletions" many different times and situations to solve this problem but with no success. I tried the following with NO success too: One of the Fields of the Record is (Month). In the Data Properties, I set a Default Value for this field as(December 2014) for instance. I set the Data Properties "Allow Additions", "Allow Edits", and "Allow Deletions" to (Yes). Then I put the following code in the Form's Current Event:
Private Sub Form_Current() If Me.month.Value = "December 2014" Then Me.AllowAdditions = True Me.AllowEdits = True Me.AllowDeletions = True
So looking at the tables, C1 = 2 C2 = 4+6 = 10 B2 = C1 + C2 + D4 = 20 A1 = 20 + 10 = 30
Here, there are 4 levels that I have to go into to get the grand total. If I did not know how many levels there were, how would I be able to do this through code? through queries if possible??
If anyone could help, that would be great! Thank you in advance.
I want to find duplicate records based on FirstName and LastName and delete the duplicate. Also, I want to delete any records which have a blank FirstName and LastName.
I have form setup with two cascading combo boxes (facility and date) to select a record (other navigation, including mousewheel, is disabled). There is a button to open another form which allows addition/deletion of records by facility and date. When this form is closed, the combo boxes update accordingly on the initial form. However, if I select a new record whose facility/date I have just entered, it seemingly shows the wrong values for several of the other fields. If I check the corresponding table, the values are actually at default, though, and when I reopen the form they have reverted to default. Any ideas on how to solve this? I'm tempted to simply have the first form close and reopen when the second is closed, but couldn't figure out the syntax to close a form with a button on a different form. Let me know if there's any more information I need to provide. Thanks for any suggestions.
I have a mainform with 4 fields which are marked with 4 primary keys: soldtoId, shiptoID, PlantId and formulaID. PlantID is a long integer number field and the other 3 are text fields. there is no default values.
I have a subform1 that is linked by PlantID and FormulaID. These 2 field names are in the linked child fields.
I had a handful of records established already. Today, i added a command in the after update section of the PlantID field in mainform by adding Me.Refresh. So when i change the plantID in the mainform, the subform gathers different plantID and formulaID data automatically. works nicely.
Here is the rub. I next tried adding NEW records to the mainform. that's the one with 4 primary fields.
i enter soldtoID and shiptoID fine. they have no refresh need. however, after the enter a PlantID, the me.refresh kicks in before i can get the the formulaID field. i get a debug error. something about a NULL. which i suspect is the formulaID that i didn't get a chance to enter to. FYI, later, i want to put a refresh on formulaID too.
so how can i make some kind of Refresh work for both New and existing records?? penwood
I have a user login code am using for users to login and only access their records in a subform according to their user ID and access level (user or admin). On the main form I have a user name field, the password field and two other fields: one to hold userID and the other to hold access level.
I also want if the person logged in has "Admin" access level the subform should return records from all users. For now what is happening is that even when I assign myself with "Admin" access level, the subform is not returning all records from other users, but my own records only. The original demo where I found the code worked well but I cannot find it and I am totally lost on this.
Here is the code I have so far:
Code: Private Sub cmdLogin_Click() Me.Hold_User_ID = Nz(DLookup("User_ID", "T_Users", "Username='" & Me.UserName & "' and pword='" & Me.PWD & "'"), -1) ' check to see if we have a good login If Me.Hold_User_ID = -1 Then MsgBox "Invalid username or password."
I have a database with a table with company names, then a relationship to another table that shows that companies' address, but I also want there to be an address 2 and 3 and so on, and some of our companies have multiple sites.So what Im asking is how would you be able to show multiple data, on a sing record.