Results 1 to 8 of 8
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    ShowDialog Alternative?

    I have a class which opens a form as dialog so I can use the form to send an email. Here is the class code:


    Code:
    ' do some class code here
    DoCmd.OpenForm "SendEmail", , , , , acDialog
    ' do more class code here AFTER the form is closed
    The class has properties needed to send an email. These properties are set before executing the above code.
    Currently, before executing the OpenForm command, I put these property values into TempVars, and the Form_Load event of the form takes the tempvars and uses them to load text boxes into the form.

    The code above of course pauses after OpenForm, since I opened it as acDialog.
    The form_Close event of the dialog form updates the TempVars with the new values from the text box, then when the form is closed, the calling class replaces the appropriate class member variables with the TempVar values and continues to run.

    The entire purpose of the form is to let the user enter his/her own values for send-to, subject, body, etc.

    Right now, this is working just fine, but seems overly complex.

    Since I have already set most of the needed properties, I thought it would be so much easier to somehow send the class object into the form and update it directly, rather than having to use TempVars.

    This is where I'm having my issue. I can define a form object as New Form_frmEmail, which will run the various events that get triggered when the form is opened, then tell the form to show itself when everything is loaded. This is where the problem occurs. If I open the form this way, it is not opened as dialog, so my calling code continues to run. This won't work.

    If I open it as acDialog instead, I can't then send the class instance (Me) to the form, because code execution has stopped.
    Is there any way to open the form NOT as dialog, but still have the calling code pause? If I recall from years past, VB6 would let you open a form hidden, then load its properties, then show it as dialog. But I don't think Access VBA can do this. Is there a work-around?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why not just display the email instead of sending it?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    Why not just display the email instead of sending it?
    Thanks for the answer, but I don't quite understand it. The class itself can send the email "silently", without opening the form at all if I load all of the properties needed. To be more flexible, I can also pop the form open and let the user type in his own message (or other fields). Either way, the class will continue with the process of sending the email. There's no way to display the email, other than choosing to pop open the form. The class does not use Outlook or any other email client. So the question is specifically how can I open a form in code as acDialog, but still pass the class object to the form. If this isn't possible, I will continue to use the TempVars method, because it does work fine. Thanks...

    Edit: Maybe I'm thinking backwards on this. Maybe the question should be: Can the form code somehow gain access to the instantiated class object instead of the class object feeding itself to the form? Maybe somehow finding the pointer to the instantiated object? If I could get a pointer value prior to opening the form, I could send that pointer in using OpenArgs???

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Ah OK, CDO?
    I am not great with classes. I can use them, but that is about it. Sorry.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    Ah OK, CDO?
    I am not great with classes. I can use them, but that is about it. Sorry.
    Thanks. Not using CDO specifically, instead I'm using a 3rd-party library which can send SMTP emails. I've never used CDO, but I'm guessing it would be similar.

    I'm thinking this is not strictly a class issue. It could just as soon be a method in a module. The issue is opening the form in code as acDialog, but still be able to populate a property or public variable in the form. Or, opening it not as acDialog, but having it act as a dialog so the calling code does not continue to execute.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I'm not sure I'm following you. Why must you pause the code?
    Are you using withevents in your class? Why not use the close event to continue on with your code?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by moke123 View Post
    I'm not sure I'm following you. Why must you pause the code?
    Are you using withevents in your class? Why not use the close event to continue on with your code?
    I have a class called clsEmail. I instantiate this class from some form's code. I set properties such as To, From, Subject, Body, etc. Then I invoke the class' SendMail method. This method builds the email, attaches the properties to it, then sends the email. This is a simple use-case, and works fine.

    Instead of knowing the To, From, Subject, Body, etc., sometimes I want to show the email form and let the user type in those values, then click the Send button. So my SendMail method took an optional argument called ShowForm, which defaults to False. If I instead invoke the SendMail method with True, it opens the form and pauses execution until the form is filled out. This is done by opening the form with acDialog option. So that is why the SendMail method pauses, because it is waiting for the user to finish filling out the form and clicking the Send button. I hope I've explained this clearly.

  8. #8
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    I have solved this issue, and would like to share how so it may help others.

    The solution is very simple. Instead of declaring the class object in the form where I am going to use it, I moved the declaration to a module and declared the class as Public. When the form is opened, it can now refer to the class object without having any special code to insert it into the form. This was so simple that I just didn't see it. Thanks for taking the trouble to reply to this thread.

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

Similar Threads

  1. Need Alternative to Union
    By greatwhite in forum Queries
    Replies: 5
    Last Post: 07-19-2019, 10:09 AM
  2. Replies: 17
    Last Post: 06-14-2018, 03:25 PM
  3. Sendkey alternative help
    By Madmax in forum Access
    Replies: 1
    Last Post: 04-10-2012, 10:46 AM
  4. Dlookup alternative
    By scotty22 in forum Queries
    Replies: 19
    Last Post: 10-26-2011, 06:20 AM
  5. alternative to autofeupdate
    By TheShabz in forum Programming
    Replies: 3
    Last Post: 07-19-2011, 11:38 AM

Tags for this Thread

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