+ Reply to Thread
Results 1 to 25 of 25

How to add input box for require record to mail?

  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    How to add input box for require record to mail?

    Hi friends,

    In the following code I want to send emails to the selected records as per the requirement of the user. At present it’s sending emails to all the records in the database. There are about 5000 records in the database. To avoid duplicate sending mails I want to insert ‘Sent’ remark in the ‘REMARK’ field. If there is ‘Sent’ remark in ‘REMARK’ field then I want to skip that record while mailing. For this I want add input box to enter the number of first and last record. How to amend the code to achieve this target?

    Please Login or Register  to view this content.
    Any help will be highly appreciated.

    Thanking you in anticipation.
    Sincerely,

    mso3

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    We have had this discussion before (see: https://www.excelforum.com/word-form...e-request.html; and https://www.excelforum.com/excel-pro...tax-error.html) and the answer hasn't changed.
    Last edited by macropod; 03-16-2017 at 06:26 PM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    As per your suggestion I tried my level best to learn mail merge. I amended the code and now the mails are delivering as per input first and last number. I didn't understand the filter as you suggested in previous thread. Please do suggest me a code to skip those records which has dash sign in 'email' field and add a remark in 'remark' field after delivering the mail. Now I'm getting error if there is a dash sign in email column.

    Please do suggest me an amendment positively in the present code because it's working fine. Only an amendment to skip record and add 'Sent' remark problem is to solve. I don't want to prolong the thread as previous to waste your time for the same problem again.

    Please Login or Register  to view this content.
    Thanking you,

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    I am still waiting to see some evidence that you've applied a mailmerge filter. Your strQry says otherwise... You might at least spend a few moments learning how to use mailmerge filters, apply the required filter to your mailmerge main document, then run the macro I gave you that will show how strQry needs to be modified.

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Thank you for your kind efforts to make me learn mail merge filter.

    Extremely sorry for not understanding apply mail merge filter. In ‘Mailing’ tab there is a option ‘Rule’ to filter the records. It’s my understanding. There is a option ‘skip it’ to exclude the records from mail merge but you said it’s not you mean. By using it I get the require output but I want to learn what is ‘apply mail merge filter’ a proper way from you. How to do it? I tried my level best to learn it but in vain. So how can I give you some evidence of ‘apply filter mail merge’? Please don’t mind. If I will learn it now then I hope that it will be my last post on this topic.

    Please Login or Register  to view this content.
    Please guide me the proper way to ‘apply filter in mail merge’ positively.

    Thanking you in anticipation.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    I have already told you how to apply a filter. The code in your posts does not do that; it tries to add SKIPIF fields to the mailmerge main document instead. To apply a Filter, you do not use the 'Rules' button to add fields*; neither do you need the macro recorder; you use the 'Edit Recipient List' button and choose 'Filter' so you can apply the Filter. Once you've done that correctly, running the TestSQL macro I provided in https://www.excelforum.com/excel-pro...ml#post4540650, will show you what your strQry string should be.

    * Of course, adding such fields to the mailmerge main document is another way of achieving the same result, but you would only do that once (manually - before saving the updated mailmerge main document); you certainly would use a macro to add it to the mailmerge main document every time you run the mailmerge.

  7. #7
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Greetings from me!

    Oops! What a silly mistake I was doing since last 2/3 month to apply filter. Now I understood what is ‘apply filter’ and got require output after running the mail merge from word. I tried to record it to put it in the mail merge macro from excel but failed; no recording. It’s very simple and easy to follow.

    Please see the attached workbook and guide me how to put that code in macro strQry string to achieve the target automatically.
    Please Login or Register  to view this content.
    Thanking you,
    Attached Files Attached Files

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    The macro is a Word macro. You run it in Word against your mailmerge main document after you have correctly set the filter. You can test whether the filter is correct by running the mailmerge from your mailmerge main document (not from Excel) and checking the output. Once the output is correct, running the macro will tell you what your strQry string should be.

  9. #9
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Thank you for your kind guidance. Now I’m getting correct output using filter. I have recorded the macro to get sql statement. I didn’t understand how to amend it in our code strQry string to make it automatic.

    Please Login or Register  to view this content.
    Thanking you,

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    I did not say to record a macro; I said to run the macro I gave you. Your recorded macro quite possibly broke the filtering that you had applied. Re-apply the filter, then run the macro I gave you.

  11. #11
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Greetings from me!

    As per your suggestion I ran the word macro you gave. It’s running fine using filter. The filtered output was correct as per requirement. You have used ‘Const StrNoChr As String = """*./\:?|"’ sql string to show what we don’t want in the sql statement. However, I didn’t understand how to amend the present email code qry statement. I don’t have any knowledge of it because I have not learned it before. By practice and a valuable guidance from you friends I learn a lot. I learned a mail merge filter function from you now and found very easy and useful. I will use it in future. Now we are very close to solve the problem. Therefore, I request you to suggest me the amendment to complete the macro positively. I have taken a lot of time to learn it and trouble you more. Do amend the code for this time; I will learn from it positively. I myself feeling very guilty to come on the forum for the same problem again and again.

    I learn a lot from you regarding mail merge. I by heart appreciate you for the same.

    Have a nice day.

    Thanking you,

  12. #12
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    Quote Originally Posted by mso3 View Post
    I ran the word macro you gave. It’s running fine using filter. The filtered output was correct as per requirement. You have used ‘Const StrNoChr As String = """*./\:?|"’ sql string to show what we don’t want in the sql statement
    That expression has nothing at all to do with the sql statement! It's sole purpose is to guard against the output documents having invalid filenames. The macro that code is for is a Word macro. If that's all you need, you don't need to modify anything once you've applied the filters.

    Previously, however, you've said you wanted to run the mailmerge from Excel - which is what the code your first post in this thread is for - and for that you would need to modify the SQL statement which, in that code, is defined by:
    Const strQry As String = "SELECT * FROM `Data$`"
    and that's what the TestSQL is to help with.

    You really do need to be clearer about your requirements and pay attention to the advice given. Most of the posts in the multiple threads you've started on this topic (contrary to the forums rules) have been due to you not doing either of those things.

  13. #13
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Sorry for misunderstanding. I have posted my problem for the code below post1 as follows:

    I want to send mails to the selected records on the following conditions:
    If there is dash sign in email id then skip record
    If there is ‘Send’ remark in column ‘REMARK’ then send mail
    ‘We have set filter for it
    After sending mail add/change remark in column ‘REMARK’ ‘Send’ to ‘Sent’
    Input box for entering the first and last record number
    I want to run the macro from excel only.

    These are my initial requirements in the first post. The macro below is run from excel and I want to run it from excel only not from word. Due to my misunderstanding I didn’t follow your instruction properly; language problem because English is not my main language. As per your guidance I learned the filter function which I found easy and useful. After that you asked me to amend the qry to get the require output from excel. Here, a problem that I didn’t understand your instruction properly. Since last 2/3 months I’m trying to achieve the require output but in vain. Today after learning the filter function we are about to very close of the final solution. I’m also feeling very sorry for troubling you for the same problem repeatedly. I’m extremely sorry for that.

    I don’t have any computer/programming degree. I learn it by practice and the valuable guidance from the forum friends like you. I request you to amend the code below to run from excel for the last time. I assure you that I will learn from it and will not post any thread on the same topic on the forum again in future. Please apologize me and do the favor to solve my problem for ever regarding mail merge from excel.

    Please Login or Register  to view this content.
    Once again sorry for trouble.

    Thanking you in anticipation.

  14. #14
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    Quote Originally Posted by mso3 View Post
    I want to send mails to the selected records on the following conditions:
    If there is dash sign in email id then skip record
    If there is ‘Send’ remark in column ‘REMARK’ then send mail
    ‘We have set filter for it
    So what is the QueryString after applying the filter????? I have given you a macro for retrieving that. You have quoted it. Yet you seem never to have used it!!!!
    Quote Originally Posted by mso3 View Post
    After sending mail add/change remark in column ‘REMARK’ ‘Send’ to ‘Sent’
    Which column in the workbook is that? And which column in the workbook contains the email ID?
    Quote Originally Posted by mso3 View Post
    Input box for entering the first and last record number
    It's not apparent to my why you need both the inputbox and the filter. The filter can be used to automatically exclude all 'Sent' records without the need for an input box. The inputbox would only be needed if there are records without 'Sent' that you still don't want to send to.
    Quote Originally Posted by mso3 View Post
    I want to run the macro from excel only.
    In that case, stop messing with Word-specific macros (e.g. post #9 ) or macros that aren't for sending emails (e.g. post #11) and follow the advice given.
    Quote Originally Posted by mso3 View Post
    I don’t have any computer/programming degree.
    Nor do I. All that I know about using MS Office, including programming, is self-taught - often drawing on the work of others who provided useful examples. Indeed, what I have posted in forums over the years has had nothing to do with the kind of work I did in my former employment and much of it has been learnt during my retirement while helping people like you solve their problems.

  15. #15
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    I have already posted my workbook containing word document, excel workbook post no. 7. Please see that again for me because the misunderstanding is still there for 'from excel and from word'. From excel I mean is; the letter is in word main document, the data is in excel workbook, the macro is in excel workbook and I want to run it from there as in the workbook attached post7.

    The email is in column 'H' and remark is in column 'V' in excel workbook.

    Due to misunderstanding we have confusion. Hope after seeing the attached workbook it will clear.

    Ok, if the filter can do the job then no need of input box for first-last record require.

    Please don't mind. I respect you and always appreciate you for your kind guidance to me and other friends on the forum.

    Please do the necessary amendments in the code and send me the final code to avoid confusion and close this thread today positively.

    thanking you in anticipation.

  16. #16
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    I will ask again:
    1. What is the QueryString after applying the filter?
    2. Since a properly-implemented filter will automatically skip records with 'Sent' in the 'Remark' column and '-' in the 'Email ID' column, why do you need the inputboxes as well?
    Until you answer both questions, I'm not going to waste any more time on this.

  17. #17
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Greetings from me!

    Glad to inform you that I have successfully amended the qry and getting correct output as per requirement.

    Now the remark and message count problem is to solve.
    After sending mail change remark 'Send' to 'Sent' in column 'V'
    At the end message how many mails sent.
    Input box for if the user wants to mail/create letter for the particular record only for duplicate receipt.

    Doubt: There are about 5000 records in the database. If we didn’t create a input box to mail particular records then ‘does it will take a long time to scan for entire sheet and send the mail or not?
    I have also create a macro for letters using the same code. If I want to create a particular record second time if there is a request of duplicate receipt then I have to delete the remark ‘Sent’ and type ‘Send’ again to create that particular record.

    Please Login or Register  to view this content.
    Thank you for your kind guidance to teach me mail merge.

    Thanking you,

  18. #18
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    The mailmerge will take about the same time to run regardless of whether you're using an input box to get the record range. Indeed, the time taken for you to input those details is likely to be far more than it would take the mailmerge for any additional processing without the input boxes. Even with input boxes, you won't be able to generate duplicates unless you also change the 'Sent' to 'Send'.

    If you want to send letters, you can't use the same code: you would either have to use another macro for that or modify the existing one so you can choose between sending letters and sending emails. You'd probably also need to use a different mailmerge main document.

    For code with the inputboxes, try:
    Please Login or Register  to view this content.
    For code without the inputboxes, try:
    Please Login or Register  to view this content.
    Note: I've simplified your Const strQry String. However, as SQL is not my forte, I can't guarantee it works correctly. Check the output.
    Last edited by macropod; 03-19-2017 at 06:15 PM.

  19. #19
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Thank you very much. Now everything is covered in the code as per requirement. In the both code I am getting error as follows:
    Getting run-time error 5922 word was unable to open the database Source
    On the following line:
    Please Login or Register  to view this content.

    Yes, for letters I have another macro.

    Thank you and have a nice time.

  20. #20
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    That may be because there's an error in my edit of your Const strQry String. As I said, SQL is not my forte. Try the code with your Const strQry String from post #17.

  21. #21
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Yes, the error was in qry. After changing the qry statement the error has gone.

    Now a error 1004:
    run-time error 1004 application-defined or object-defined error on the following line ...
    Please Login or Register  to view this content.
    Thanking you,

  22. #22
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    Oops - typos in the With ThisWorkbook.Sheets("Data") ... End With block. I've edited that part of the code in post #18. Try the updated With ThisWorkbook.Sheets("Data") ... End With block.

  23. #23
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Greetings from me!

    Excellent! Now it’s working fine as per requirement.

    I have also created a macro for letters. I amended the email code and achieve the target as per requirement successfully. Only the remark ‘Send’ to ‘Sent’ and letters count message at the end is not as per requirement. I couldn’t amend it. Everything is perfect. I’m marking the thread solved now but do suggest me an amendment in the letter code positively remark and letter count problem. I have created a new letter and one more column for letter remark namely ‘REMARK L’ column ‘W’.

    After a long time finally I learned mail merge, sql statement, filter with your kind guidance and sincere efforts to teach me positively. I’m thank you for the same and appreciate you by heart.

    Please Login or Register  to view this content.
    Thank you and have a nice time.

  24. #24
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to add input box for require record to mail?

    Quote Originally Posted by mso3 View Post
    I have also created a macro for letters. I amended the email code and achieve the target as per requirement successfully. Only the remark ‘Send’ to ‘Sent’ and letters count message at the end is not as per requirement. I couldn’t amend it. Everything is perfect. I’m marking the thread solved now but do suggest me an amendment in the letter code positively remark and letter count problem. I have created a new letter and one more column for letter remark namely ‘REMARK L’ column ‘W’.
    In that case:
    • change the With ThisWorkbook.Sheets("Data") ... End With block for the MergeToLetterWithPrompt sub to:
    Please Login or Register  to view this content.
    • change the With ThisWorkbook.Sheets("Data") ... End With block for the MergeToLetterNoPrompt sub to:
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: How to add input box for require record to mail?

    Hi Paul,

    Perfect! In this thread I learned a lot; 4 types of mail merge, filter, count message and remark. Credit goes to you for your kind guidance to teach me it patiently.

    I by heart appreciate you for the same.

    Thank you and have a nice time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help require to get date in dd mm yyyy format in mail merge letter
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2015, 09:57 AM
  2. [SOLVED] Help require to record date and time
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 12-18-2014, 12:18 PM
  3. [SOLVED] Require help to correct a formula and send mail from excel
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2014, 12:02 PM
  4. Excel VBA mail, TO: require a vlookup
    By angel2903 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-29-2014, 02:50 PM
  5. Replies: 0
    Last Post: 10-17-2013, 12:46 PM
  6. Auto filter input box require
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2013, 09:55 PM
  7. Have cell require input before saving.
    By couriced in forum Excel General
    Replies: 1
    Last Post: 10-20-2005, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1