|
Dave Kreskowiak wrote: Trupti Mehta wrote:
Can I perform Mail merge in RTF file using Wod with my application.
Again, I ask you, since you already have Word, why are you re-inventing the wheel?? Why not just do this whole thing in Word and forget coding a solution to a problem that already has a solution??
Dave, then you tell me, if a client wants such feature in his software, how do i implement it. I have the customers DB. Client wants B, I, U .. features, so Rich text box is required. Client want to write new/edit letter and Prepare mail merge the letter to selected customers and facility to print the leters.
Now what and how to do, can you please suggest me! I would be glad to know some solution that you have in your mind for this kind of application. I am using VB.NET 2005 and MS ACcess DB.
Thanks
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: Now what and how to do, can you please suggest me!
What have we been doing for this entire thread??
Listen. Mail Merge is a very SIMPLE string replacement:
Dim text As String = "This is some text <<withAtag>> in it!"
Dim data As String = "with a tag replaced"
Dim mergedText As String = text.Replace("<<withAtag>>", data)
The value of mergedText will be "This is some text with a tag replaced in it!" . If this is beyond your comprehension, you've got no hope of completing this project.
If you can't get any data out of a database, you've got no hope of completing this project.
If you don't understand how a RichTextBox formats text, you've got no hope of completing this project.
|
|
|
|
|
Hi Dave,
Dave, thanks for your help so far. This is not just replacing text in RichTextBox. As mentioned earlier, RTB is used to just create letters. Actual Mail Merge is done later, seperately. If it was just replacing text once, thats not a big deal at all. I really tried very hard, looked on net a lot. But still can't find proper way out to replace the text for the same letter for all records in the dataset. Letter is written using RTb, saved, text like <<companyname>>, etc are added in the letter. On selection of letter and customers selected, This is the code that is fired to perform actual Mail Merge.
<br />
Private Sub PerformMailMerge()<br />
Dim wApp As New Word.Application<br />
Dim wDoc As Word.Document<br />
Dim wMailMerge As Word.MailMerge<br />
<br />
wDoc = wApp.Documents.Open(Me.CapFileName)<br />
wApp.Visible = True<br />
<br />
wMailMerge = wDoc.MailMerge()<br />
wMailMerge.CreateDataSource(mDs)<br />
<br />
Dim i As Integer<br />
Dim str As String = ""<br />
Dim addThe As Boolean<br />
<br />
Dim row As DataRow<br />
For i = 0 To mDs.Tables(0).Rows().Count() - 1<br />
MsgBox("Row of " + myDG.Rows(i).Cells(1).ToString())<br />
If (myDG.Rows(i).Cells("Select").Selected() = True) Then<br />
row = mDs.Tables(0).Rows(i)<br />
str = row.Item("name").ToString()<br />
' If name is not present, refer to The Propriertor<br />
If (String.IsNullOrEmpty(str)) Then<br />
'Replace("<<Title>>", "The")<br />
'Replace("<<ContactName>>", "Propriertor")<br />
addThe = True<br />
Else<br />
'Replace("<<Title>>", row.Item("namePrefix").ToString())<br />
'Replace("<<ContactName>>", row.Item("name").ToString())<br />
addThe = False<br />
End If<br />
<br />
'Replace("<<CompanyName>>", row.Item("CompanyName").ToString())<br />
'Replace("<<Add1>>", row.Item("Add1").ToString())<br />
'Replace("<<Add2>>", row.Item("Add2").ToString())<br />
'Replace("<<Add3>>", row.Item("Add3").ToString())<br />
'Replace("<<City>>", row.Item("City").ToString())<br />
'Replace("<<County>>", row.Item("County").ToString())<br />
'Replace("<<Code>>", row.Item("Code").ToString())<br />
<br />
'Replace("<<Date>>", Date.Today)<br />
MsgBox("Added The " + addThe + " Or Name to " + row.Item("CompanyName").ToString())<br />
End If<br />
Next<br />
<br />
' Perform Mail Merge<br />
wDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument<br />
wDoc.MailMerge.Execute()<br />
<br />
' Close the original letter<br />
'wDoc.Saved = True<br />
'wDoc.Close()<br />
<br />
'' Release References<br />
'wApp = Nothing<br />
'wDoc = Nothing<br />
'wMailMerge = Nothing<br />
End Sub<br />
As you advised earlier, I had added tags like <<companyname>> in the rtf file while creating letter. To do the mail merging stuff, I found this the only way out. I believe you can help me out. I have everyhting with me, just don't know how to so it. I agree something is still incorrect and missing in this code.
Please help me and let me know if what I am doing is right or am in any wrong path. Please my deadline is on, and got to finish this. I request you and hope, you will help.
Thanks
Terry
|
|
|
|
|
OK. So you have Word installed on the machine, since you're using it in your code.
Why are you even bothering with this?? The user can easily do the exact same thing in Word, using Word's own field and MialMerge features and have greater flexibility doing it!
You're code is opening an RTF file in Word and trying to use Word's MailMerge, which won't work because you're not using any field objects that Word needs to do mail merge.
Then your code does something really weird here:
Dim row As DataRow
For i = 0 To mDs.Tables(0).Rows().Count() - 1
MsgBox("Row of " + myDG.Rows(i).Cells(1).ToString())
If (myDG.Rows(i).Cells("Select").Selected() = True) Then
...
This says increment i from 0 to the number of rows in a DataTable object, but your index is looking at the rows in a DataGrid instead. Just get the data out of the DataRow object returned by:
mDs.Tables(0).Rows(i)
That gives you the DataRow with all the data in it.
You really need to scrap this code and start over, from the specifications. What you told me and what you've shown me are two VERY different things. I thought you were doing this in VB.NET with a RichTextBox and you've shown me VBA code, that's running in Word apparently.
|
|
|
|
|
Dear,
The client wants this kind of feature in his application. I agree Word can do it in a much better way, but client is boss. If he wants in the application only then ?
The application is written in VB.NET with MS Access DB. It uses RTB to let the user write letters. Letters are saved as an RTB. Earlier also, I mentioned clearly, that letters will be used later to perform mail merge.As you had advised to put any sort of tag in rtb, so i inserted <<companyname>> type of tag. My Q. from start is this only, how will I change this text to perform mail merge.
On doing lots of research I cam to know that Mail Merge can be done by using Word in out VB.NET code. I found that also, that the document need to have some fields of Words Mail Merge set. I had always heard from you, that Mail Merge part is very simple and easy, but how it was in my case, I never got an idea for that.
Code checks for Selected records from the datagrid which displays all records of the dataset. So, even after dataset, records are filtered by selected (Checkbox) or not.
<br />
row = mDs.Tables(0).Rows(i)<br />
.....<br />
'Replace("<<Title>>", row.Item("namePrefix").ToString())<br />
Instead of writting the whole stuff again & again, I have set to a datarow, & then row.Item(....) I didn't knew how to replace the tag contents with the data, so had just written this code to give a proper flow.
Regarding working from scratch, fine, then as per specs.,
1. Create Letters (Add/Edit/Save ... Formatting) FINISHED
2. Added tags in form of Text FINISHED
3. Ability to select Customers FINISHED
4. Do Mail Merge on selected letter to selected custoemrs ?????
What changes should be done. dOES STEP 2 NEED to be looked at and worked out some other way out.
Looking for your reply.
I apologize for reposting, but as this thread wasn't getting better, so posted with latest query.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: I mentioned clearly, that letters will be used later to perform mail merge.As you had advised to put any sort of tag in rtb, so i inserted <<companyname>> type of tag. My Q.
Yep, but that's before your code said you were using Word to do the Mail Merge. Is this still the case??
Trupti Mehta wrote: from start is this only, how will I change this text to perform mail merge.
If you're still using Word to do the Mail Merge, you'll have to load the document into Word, scan it for any <<&& tags and replace them with Word field codes. Don't ask me how to do it, I don't do Office Interop.
Trupti Mehta wrote: I had always heard from you, that Mail Merge part is very simple and easy, but how it was in my case, I never got an idea for that.
If you're using Word to do the Mail Merge, this all changes.
If not, it's still bloody easy. Match the field in teh database with the field in the document and replace that field with the data retrieved from the database. It's a simple string replacement!
Trupti Mehta wrote: Code checks for Selected records from the datagrid which displays all records of the dataset. So, even after dataset, records are filtered by selected (Checkbox) or not.
Now you're changing the the applications requirements...
Trupti Mehta wrote: 4. Do Mail Merge on selected letter to selected custoemrs ?????
Again. This is easy. You have the data from the database already. All you have to do is get each record that's selected from the DataGrid, find and replace the tag for that field in the document and replace the tag with the data from that field.
Database:
FirstName LastName Address
Joe Schmo 123 Anywhere
Document:
Hi <<FirstName>>! You're at <<Address>>!
Replacing the tags with the data from each record is just a simple string replacement.
Dim documentText As String = RTB1.RTF.Replace(tag, fieldData)
|
|
|
|
|
Dave, forget abt Word. That came in picture as I didn't find any other way to do mail merge. But their are other possibilities, I am open.
Fine. So after selected customers & letter, I load the letter in an RTB (not visible to client), for first record, change the data with the fields. Then before going to second record, I need to do somehting, that will insert a page break, copy the template again & then again I loop with the data replace stuff.
Dave, help me understand 1 point, how will i do the page break stuff. As for each customer, the letter contents will remain the same but the address & name will change & each will be on a seperate page of the same document preferred. Previously also I never found out a way to work out at this point. Which made me rethink, how can this operation be performed just by a RTB. And on searching the net, everywhere I found was working with Word. No other alternative.
But, if you could give me this alternative, I would be really glad, that finally the solution worked out. Everything else, what you mentioned can be done with ease. That all is not at all a probelm.
I hope you can throw a bit of more light on it.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: how will i do the page break stuff.
AFAIK, the RTB doesn't support page breaks since it knows nothing of page size.
|
|
|
|
|
<blockqote>
Trupti Mehta wrote:
4. Do Mail Merge on selected letter to selected custoemrs ?????
Again. This is easy. You have the data from the database already. All you have to do is get each record that's selected from the DataGrid, find and replace the tag for that field in the document and replace the tag with the data from that field.
Database: FirstName LastName Address Joe Schmo 123 Anywhere Document: Hi <<firstname>>! You're at <>!
Replacing the tags with the data from each record is just a simple string replacement.
Dim documentText As String = RTB1.RTF.Replace(tag, fieldData)
Dave Kreskowiak wrote: the RTB doesn't support page breaks since it knows nothing of page size.
Hmm, So their doesn't seem a way out to create a letter for each customer in a same document. Got to save each customer letter in a seperate file is only left out, I think. And then to print each document.
Can you get the level of difficulty and solution for the same now. I appreciate your solutions.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: Hmm, So their doesn't seem a way out to create a letter for each customer in a same document. Got to save each customer letter in a seperate file is only left out, I think. And then to print each document.
Yep.
Trupti Mehta wrote: Can you get the level of difficulty and solution for the same now.
Sometimes re-inventing the wheel isn't worth it.
|
|
|
|
|
Hai
I want to a lanch a excel file using vb6.0. The excel file is a online updatable file and contains more macros for online updation...
so i need to launch the excel file so that it automatically enable the macro and automatic update..
Plz anyone can assist me
Thank u
|
|
|
|
|
If you're talking about launching the Excel file (*.xls) without any further automation, then you can just use the Shell command to launch it.
h = Shell("C:\fully\qualified\pathToFile.xls")
|
|
|
|
|
hi all,
i am really stuck at how one would write textbox does not equal array.
here is the code, i even tried <> but is does not work.
please help me.
If txtModID.Text "does not equal" (arrPlayer(intctr).intPlayerID) Then
thankyou in advance.
your help is much appreciated
Unicept
|
|
|
|
|
You could use ToString to compare them as strings, or you could use int.TryParse to see if the text is an int, then compare those. You can't compare two objects of different types unless an implicit conversion exists.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
if u want to comp[are objects like strings, or any of ur own objects then use
"NOT obj1.equals(obj2)" this will return a boolean result, and ifr u want to compare any # then use
num1 <> num1 ill return false if both # r true.. hope it will help
(Jameel)
|
|
|
|
|
If you are using vb.net you can simply loop through your array with the string.compare method:
For each StringElement in YourArrayOfStrings()<br />
If txtModID.Text.Compare(String) > 0 then<br />
'do something<br />
End If<br />
Next
Hope this helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
How to get detail dscription of error numbers in VB6
Thank in advance
|
|
|
|
|
Err.Description is all the description you're going to get.
|
|
|
|
|
Can any one tell me what is the use of delegate in .NET
Thanks in advance
Ahamed Azeem
|
|
|
|
|
It is used to call a method in another class, such as an event, or to notify one class of something that happens in another.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
thanks a lot.
Could u please explain little bit detail?
Ahamed Azeem
|
|
|
|
|
If you want more detail, try googling for some articles on it. They will provide more and better detail than I will on the fly
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Dear All,
I am using VB.NET 2003 and MS Access 2003 and my project is always used the database.
Pls check this code,
Public Sub DR()
..........
............
Dim drd1 As System.Data.OleDb.OleDbDataReader
SelectedDataReader(drd1)
Do While drd1.Read
Dim a As Integer
price(a) = drd1.GetDouble(0)
a = a + 1
Loop
drd1.Close()
...............
..........
............
End Sub
Data reader is in another module.
Module CUFA
............
...............
Public Sub SelectedDataReader(ByRef drd1)
Dim cmd1 As New System.Data.OleDb.OleDbCommand
cmd1.Connection = cnn1
cmd1.CommandText = "SELECT Price FROM Selected"
Try
drd1 = cmd1.ExecuteReader
Catch ex As SystemException
End Try
cmd1.Dispose()
End Sub
...........
...........
End Module
Pls let me know is this correct?
And data connection is opened another module. It opens starting of my project and closes end of my project. During that time more than 200 data readers and commands open and close.
Dimuthu
Dimuthu
|
|
|
|
|
To do what??
As far as your code goes, it's a lousy design. That's about all I can say about this....
dimuthuvbnet wrote: And data connection is opened another module.
Why?? Why not just have a method in your DAL that creates a DataReader for your command and returns it?? Why are you creating a DataReader in one place, creating a command for it in another, using a "global" variable for a connection, chosing bad names for your methods, using two different classes/modules to build this reader, ..., need I continue??
You're really missing the point of encapsulation. This code can be done in a single class, using at a minimum, 2 methods, and a max of 4. One method to retrieve the connection string from a config file, a second to create a connection object (it's also acceptable to combine these first two into one method), and a third to create the data reader. You may either return the data reader, or create another method to use the datareader to create your array, though there are other methods of doing what your code looks like it's doing.
|
|
|
|
|
Hi,
I am using VB.NET 1.1 on a Windows application. It is an import program. There is a start and stop time, during these 2 times the back is run so the import program should pause. How do I check if every second if the current time is out of the time range so that I can resume the import program after the stop time.
So if I type in 19:00 for the start time and 02:00 time then the program pauses, so I will need to know when it is 1 second past 02:00 so that the import can continue.
Regards
.NET Enthusiast
|
|
|
|
|