Results 1 to 11 of 11
  1. #1
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110

    Pass on filter from one form to the next.

    I have a form that lists members. It includes an e-mail field. I've created a button control that will allow the user to send to all the members with e-mails or to a filtered list of e-mails. What I would like to do now is create a similar button that can send to either the entire list or a filtered list, but prior to sending I want to display a form to request input for the message body. This will be for quick messages, like a text message. Basically I want to filter the list, then click the button, a form will popup with one text box to type the message, the user enters the text, and then they hit send to send the message.

    Here's the code I have now:

    Dim strRS As String
    strRS = "Select * FROM MembersExt "
    Dim strWhere As String
    strWhere = ""
    If Me.FilterOn = True Then
    strWhere = Me.Filter
    strRS = strRS & " WHERE " & strWhere


    End If
    Dim appOutLook As Outlook.Application
    Dim oEmailItem As MailItem
    Dim rs As Recordset
    Dim recipientList As String
    If appOutLook Is Nothing Then
    Set appOutLook = New Outlook.Application
    End If
    Set oEmailItem = appOutLook.CreateItem(olMailItem)
    With oEmailItem
    Set rs = CurrentDb.OpenRecordset(strRS)
    If rs.RecordCount > 0 Then
    rs.MoveFirst
    Do Until rs.EOF
    If IsNull(rs![E-mail]) Then
    rs.MoveNext
    Else
    recipientList = recipientList & rs![E-mail] & ";"
    .BCC = recipientList
    rs.MoveNext
    End If
    Loop
    Else
    MsgBox "No one in this group has an email address"
    End If
    Set rs = Nothing
    .TO = ""
    .CC = ""
    .Subject = ""
    .Display
    End With
    Set oEmailItem = Nothing
    Set appOutLook = Nothing

    Any suggestions

  2. #2
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Thinking about it some more I think that it would make sense that when the button control is clicked that it first brings up the form to enter the message body then when the user clicks the button in the message form it closes the form and passes the value on to the routine and sends the message. Just trying to wrap my head around how to code it.

  3. #3
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Also the code to execute the sending of the message needs to wait until the message has been entered in the message form.

    On the message form there will be a button to cancel which will need to close the message form and cancel execution of the rest of the code.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can open the message form with acDialog parameter. This will pause code execution by the first form until second form closes. Options for passing the body text back to the main form code are:

    1. global variable declared in a general module so both forms can reference it or use TempVars variable

    2. code in message form can set value of a textbox on the main form
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Ok. I have the acDialog set. Can you give me an example of how you would declare a global variable or use a TempVars variable.?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I've never used TempVars so will let you research that if you have interest.

    As for a global variable, create a general module if you don't already have one. In the module header declare a public variable, like:

    Public gstrBody As String
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    I have the global variable working. Now what I need is when I press the cancel button on the message form that it closes the message window and exits the code.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You want to allow user to abort the email from the message form? Again, pass value back to the first form. Same options for methods. Then code in first form:

    If booCancel = False Then
    'code to send email
    ...
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Thanks for the help. I have it working as I wanted now.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Ooops. Boolean might not be the best variable choice. The default state of Boolean is False. So unless you have code in the message form to set it True, it will always return False to the main form.

    Could use a string variable and have the message form set it in Cancel button event. Then the test by main form would be like: If strContinue = "" Then

    Also, at the end of the mail procedure need to reset the global variable back to its original state, in case want to run procedure again before closing db. Once set, the variable will hold value until code process is interrupted by runtime error or db is closed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Actually I did add code to do that. If they click the cancel button it sets the value to True and if they click the send button it sets the value to false. I also added code to reset the global variable.

    Once again thanks for the help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. filter date from Query pass down to report
    By geraldk in forum Reports
    Replies: 1
    Last Post: 08-17-2012, 10:14 AM
  2. Replies: 28
    Last Post: 03-08-2012, 06:47 PM
  3. Pass Subform filter to subform in report
    By camftm in forum Programming
    Replies: 16
    Last Post: 07-19-2011, 07:12 AM
  4. Pass a Form Filter to a Query
    By kenton.l.sparks@gmail.com in forum Programming
    Replies: 4
    Last Post: 04-01-2011, 11:48 AM
  5. Pass subform filter to a report
    By dinorbaccess in forum Reports
    Replies: 3
    Last Post: 01-10-2011, 05:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums