New to automation - a couple questions - MS Word 97
Author |
Message |
Tony Vroly #1 / 3
|
 New to automation - a couple questions - MS Word 97
I have been lurking and haven't found my answers so forgive me if this is a bit newbie. Also forgive the coding if it is bad. It does work however. 1. I am doing some automation from Access 97 to Word 97. All works good except when moving a currency value. The automation does not input the decimal and 2 places past the decimal. For example if the value in the table/query is "$10.00", all the automation moves over is "10". I can input the dollar sign in the Word template just before the bookmark but is there a way to get the automation to put in the decimal and 2 places past? (Also if the value is "$10.10" I get "10.1") 2. Similar to #1 - Can I format the Zip and Social Sec Number to include the hyphen where applicable? 3. Can I tell automation to skip a bookmark if the table/query field is blank? I would like to be able to have it print automatically, but can't since the user usually has to make a few formating changes before printing. Here is the code I am using now, if you have other suggestions, feel free.... Public Sub ParticipantLetter(DistributionID As Long) Dim dbC As Database Dim qryDistribution As QueryDef Dim recDistribution As Recordset Dim objWord As Word.Application ' word object Dim objDoc As Object ' document object Set dbC = CurrentDb() Set qryDistribution = dbC.QueryDefs("Distributions-Export") qryDistribution.Parameters("PID") = DistributionID Set recDistribution = qryDistribution.OpenRecordset() If recDistribution.EOF Then MsgBox "The Distribution with an ID of " & DistributionID & " could not be found.", _ vbCritical, "Distribution Not Found" Exit Sub End If Set objWord = New Word.Application objWord.Visible = True Set objDoc = objWord.Documents.Add("G:\Data\Database\Templates\ParticipantForms.dot") InsertTextAtBookmark objWord, objDoc, "J", recDistribution("Plan Name") InsertTextAtBookmark objWord, objDoc, "A", recDistribution("FirstName") InsertTextAtBookmark objWord, objDoc, "B", recDistribution("LastName") InsertTextAtBookmark objWord, objDoc, "C", recDistribution("Address1") InsertTextAtBookmark objWord, objDoc, "E", recDistribution("City") InsertTextAtBookmark objWord, objDoc, "F", recDistribution("State") InsertTextAtBookmark objWord, objDoc, "G", recDistribution("Zip") InsertTextAtBookmark objWord, objDoc, "H", recDistribution("FirstName") InsertTextAtBookmark objWord, objDoc, "I", recDistribution("LastName") InsertTextAtBookmark objWord, objDoc, "B2", recDistribution("Plan Name") InsertTextAtBookmark objWord, objDoc, "W", recDistribution("FirstName") InsertTextAtBookmark objWord, objDoc, "X", recDistribution("LastName") InsertTextAtBookmark objWord, objDoc, "Y", recDistribution("Address1") InsertTextAtBookmark objWord, objDoc, "A1", recDistribution("City") InsertTextAtBookmark objWord, objDoc, "A2", recDistribution("State") InsertTextAtBookmark objWord, objDoc, "A3", recDistribution("Zip") InsertTextAtBookmark objWord, objDoc, "A4", recDistribution("SocialSecurityNumber") InsertTextAtBookmark objWord, objDoc, "A5", recDistribution("HomePhone") InsertTextAtBookmark objWord, objDoc, "B3", recDistribution("Plan Name") InsertTextAtBookmark objWord, objDoc, "A6", recDistribution("FirstName") InsertTextAtBookmark objWord, objDoc, "A7", recDistribution("LastName") InsertTextAtBookmark objWord, objDoc, "A8", recDistribution("SocialSecurityNumber") InsertTextAtBookmark objWord, objDoc, "A9", recDistribution("FirstName") InsertTextAtBookmark objWord, objDoc, "B1", recDistribution("LastName") objDoc.SaveAs "C:\My Documents\DistributionFormsParticipant" End Sub
|
Fri, 12 Mar 2004 22:46:25 GMT |
|
 |
Simon Lewi #2 / 3
|
 New to automation - a couple questions - MS Word 97
Hi, 1. Use the Format function to format the data before inserting it into the document. For example (assuming Premium is a currency field), use InsertTextAtBookmark objWord, objDoc, "ZZZ", Format$(recDistribution("Premium"), "Currency") rather than InsertTextAtBookmark objWord, objDoc, "ZZZ", recDistribution("Premium") 2. Same principle. 3. Use IsNull to test whether a field is empty, e.g.: If Not IsNull(recDistribution("Plan Name")) Then InsertTextAtBookmark objWord, objDoc, "J", recDistribution("Plan Name") Endif ---- Simon Lewis
Quote: > I have been lurking and haven't found my answers so forgive me if this is a > bit newbie. Also forgive the coding if it is bad. It does work however. > 1. I am doing some automation from Access 97 to Word 97. All works good > except when moving a currency value. The automation does not input the > decimal and 2 places past the decimal. For example if the value in the > table/query is "$10.00", all the automation moves over is "10". I can input > the dollar sign in the Word template just before the bookmark but is there a > way to get the automation to put in the decimal and 2 places past? (Also if > the value is "$10.10" I get "10.1") > 2. Similar to #1 - Can I format the Zip and Social Sec Number to include the > hyphen where applicable? > 3. Can I tell automation to skip a bookmark if the table/query field is > blank? > I would like to be able to have it print automatically, but can't since the > user usually has to make a few formating changes before printing. Here is > the code I am using now, if you have other suggestions, feel free.... > Public Sub ParticipantLetter(DistributionID As Long) > Dim dbC As Database > Dim qryDistribution As QueryDef > Dim recDistribution As Recordset > Dim objWord As Word.Application ' word object > Dim objDoc As Object ' document object > Set dbC = CurrentDb() > Set qryDistribution = dbC.QueryDefs("Distributions-Export") > qryDistribution.Parameters("PID") = DistributionID > Set recDistribution = qryDistribution.OpenRecordset() > If recDistribution.EOF Then > MsgBox "The Distribution with an ID of " & DistributionID & " could not > be found.", _ > vbCritical, "Distribution Not Found" > Exit Sub > End If > Set objWord = New Word.Application > objWord.Visible = True > Set objDoc = > objWord.Documents.Add("G:\Data\Database\Templates\ParticipantForms.dot") > InsertTextAtBookmark objWord, objDoc, "J", recDistribution("Plan Name") > InsertTextAtBookmark objWord, objDoc, "A", recDistribution("FirstName") > InsertTextAtBookmark objWord, objDoc, "B", recDistribution("LastName") > InsertTextAtBookmark objWord, objDoc, "C", recDistribution("Address1") > InsertTextAtBookmark objWord, objDoc, "E", recDistribution("City") > InsertTextAtBookmark objWord, objDoc, "F", recDistribution("State") > InsertTextAtBookmark objWord, objDoc, "G", recDistribution("Zip") > InsertTextAtBookmark objWord, objDoc, "H", recDistribution("FirstName") > InsertTextAtBookmark objWord, objDoc, "I", recDistribution("LastName") > InsertTextAtBookmark objWord, objDoc, "B2", recDistribution("Plan Name") > InsertTextAtBookmark objWord, objDoc, "W", recDistribution("FirstName") > InsertTextAtBookmark objWord, objDoc, "X", recDistribution("LastName") > InsertTextAtBookmark objWord, objDoc, "Y", recDistribution("Address1") > InsertTextAtBookmark objWord, objDoc, "A1", recDistribution("City") > InsertTextAtBookmark objWord, objDoc, "A2", recDistribution("State") > InsertTextAtBookmark objWord, objDoc, "A3", recDistribution("Zip") > InsertTextAtBookmark objWord, objDoc, "A4", > recDistribution("SocialSecurityNumber") > InsertTextAtBookmark objWord, objDoc, "A5", recDistribution("HomePhone") > InsertTextAtBookmark objWord, objDoc, "B3", recDistribution("Plan Name") > InsertTextAtBookmark objWord, objDoc, "A6", recDistribution("FirstName") > InsertTextAtBookmark objWord, objDoc, "A7", recDistribution("LastName") > InsertTextAtBookmark objWord, objDoc, "A8", > recDistribution("SocialSecurityNumber") > InsertTextAtBookmark objWord, objDoc, "A9", recDistribution("FirstName") > InsertTextAtBookmark objWord, objDoc, "B1", recDistribution("LastName") > objDoc.SaveAs "C:\My Documents\DistributionFormsParticipant" > End Sub
|
Sat, 13 Mar 2004 02:26:36 GMT |
|
 |
Tony Vroly #3 / 3
|
 New to automation - a couple questions - MS Word 97
Referring to problem 1, I tried it but it didn't work. It seems to have no effect at all. Doesn't solve my problem nor make it any worse. No errors. I changed... InsertTextAtBookmark objWord, objDoc, "K", recDistribution("GrossAmount") to... InsertTextAtBookmark objWord, objDoc, "K", Format$(recDistribution("GrossAmount"), "Currency") And I still get problems. Some values show up without deciomals others go 3 past the decimal depending on the value. Just to check, I looked at the query and the fields are formated as currency both in the query and the underlying table. I ran the query alone and the numbers come out correctly formated. More help please?! Tony
Quote: > Hi, > 1. Use the Format function to format the data before inserting it into the > document. For example (assuming Premium is a currency field), use > InsertTextAtBookmark objWord, objDoc, "ZZZ", > Format$(recDistribution("Premium"), "Currency") > rather than > InsertTextAtBookmark objWord, objDoc, "ZZZ", recDistribution("Premium") > 2. Same principle. > 3. Use IsNull to test whether a field is empty, e.g.: > If Not IsNull(recDistribution("Plan Name")) Then > InsertTextAtBookmark objWord, objDoc, "J", recDistribution("Plan Name") > Endif > ---- > Simon Lewis
> > I have been lurking and haven't found my answers so forgive me if this is > a > > bit newbie. Also forgive the coding if it is bad. It does work however. > > 1. I am doing some automation from Access 97 to Word 97. All works good > > except when moving a currency value. The automation does not input the > > decimal and 2 places past the decimal. For example if the value in the > > table/query is "$10.00", all the automation moves over is "10". I can > input > > the dollar sign in the Word template just before the bookmark but is there > a > > way to get the automation to put in the decimal and 2 places past? (Also > if > > the value is "$10.10" I get "10.1") > > 2. Similar to #1 - Can I format the Zip and Social Sec Number to include > the > > hyphen where applicable? > > 3. Can I tell automation to skip a bookmark if the table/query field is > > blank? > > I would like to be able to have it print automatically, but can't since > the > > user usually has to make a few formating changes before printing. Here is > > the code I am using now, if you have other suggestions, feel free.... > > Public Sub ParticipantLetter(DistributionID As Long) > > Dim dbC As Database > > Dim qryDistribution As QueryDef > > Dim recDistribution As Recordset > > Dim objWord As Word.Application ' word object > > Dim objDoc As Object ' document object > > Set dbC = CurrentDb() > > Set qryDistribution = dbC.QueryDefs("Distributions-Export") > > qryDistribution.Parameters("PID") = DistributionID > > Set recDistribution = qryDistribution.OpenRecordset() > > If recDistribution.EOF Then > > MsgBox "The Distribution with an ID of " & DistributionID & " could > not > > be found.", _ > > vbCritical, "Distribution Not Found" > > Exit Sub > > End If > > Set objWord = New Word.Application > > objWord.Visible = True > > Set objDoc = > > objWord.Documents.Add("G:\Data\Database\Templates\ParticipantForms.dot") > > InsertTextAtBookmark objWord, objDoc, "J", recDistribution("Plan Name") > > InsertTextAtBookmark objWord, objDoc, "A", recDistribution("FirstName") > > InsertTextAtBookmark objWord, objDoc, "B", recDistribution("LastName") > > InsertTextAtBookmark objWord, objDoc, "C", recDistribution("Address1") > > InsertTextAtBookmark objWord, objDoc, "E", recDistribution("City") > > InsertTextAtBookmark objWord, objDoc, "F", recDistribution("State") > > InsertTextAtBookmark objWord, objDoc, "G", recDistribution("Zip") > > InsertTextAtBookmark objWord, objDoc, "H", recDistribution("FirstName") > > InsertTextAtBookmark objWord, objDoc, "I", recDistribution("LastName") > > InsertTextAtBookmark objWord, objDoc, "B2", recDistribution("Plan Name") > > InsertTextAtBookmark objWord, objDoc, "W", recDistribution("FirstName") > > InsertTextAtBookmark objWord, objDoc, "X", recDistribution("LastName") > > InsertTextAtBookmark objWord, objDoc, "Y", recDistribution("Address1") > > InsertTextAtBookmark objWord, objDoc, "A1", recDistribution("City") > > InsertTextAtBookmark objWord, objDoc, "A2", recDistribution("State") > > InsertTextAtBookmark objWord, objDoc, "A3", recDistribution("Zip") > > InsertTextAtBookmark objWord, objDoc, "A4", > > recDistribution("SocialSecurityNumber") > > InsertTextAtBookmark objWord, objDoc, "A5", recDistribution("HomePhone") > > InsertTextAtBookmark objWord, objDoc, "B3", recDistribution("Plan Name") > > InsertTextAtBookmark objWord, objDoc, "A6", recDistribution("FirstName") > > InsertTextAtBookmark objWord, objDoc, "A7", recDistribution("LastName") > > InsertTextAtBookmark objWord, objDoc, "A8", > > recDistribution("SocialSecurityNumber") > > InsertTextAtBookmark objWord, objDoc, "A9", recDistribution("FirstName") > > InsertTextAtBookmark objWord, objDoc, "B1", recDistribution("LastName") > > objDoc.SaveAs "C:\My Documents\DistributionFormsParticipant" > > End Sub
|
Sat, 13 Mar 2004 04:57:45 GMT |
|
|
|