Results 1 to 8 of 8
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    Declarations Module

    Since I fought through the Date Format Function Module I now want to figure out how to set up a declarations module for email Variables:



    Code:
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookMsg1 As Outlook.MailItem
    Dim objOutlookMsg2 As Outlook.MailItem
    Dim objOutlookAttach As Outlook.Attachment
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    Set objOutlookMsg1 = objOutlook.CreateItem(olMailItem)
    Set objOutlookMsg2 = objOutlook.CreateItem(olMailItem)
    Later one to set up normal variables

    I tried the following:

    Code:
    Function Decaredl()
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookMsg1 As Outlook.MailItem
    Dim objOutlookMsg2 As Outlook.MailItem
    Dim objOutlookAttach As Outlook.Attachment
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    Set objOutlookMsg1 = objOutlook.CreateItem(olMailItem)
    Set objOutlookMsg2 = objOutlook.CreateItem(olMailItem) 
    End Function
    and put Declared in place of the code for the email. The code couldn't find the variables.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    Public objOutlook As Outlook.Application
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    pbaldy
    I tried that instead of function and got an error on the Dim ObjOutlook as vague. Changed the name to Public Email As Outlook.Application. No issues there, code ran through. In the Form_Start where I have the email code I put ' before all the Dim Outlook variables. Put Declared, Module_Declared, Module_Declared.Email, Call Module_Declared etc. - Error on Expected Procedure not Variable. Call Module_Declared = Sub or function not defined.

    Changed all the Dim in the function to Public without the Function/ With the function. If I put the function in , I cannot have Public

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    If I understand your goal, I think what you want is a class module. That is, you want a custom object with custom properties that you can assign and retrieve with the Let and Get statements. Google 'class module' if you don't know what I mean.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I recommend you review this Microsoft material and google anything you don't understand.

    In your previous/related post, there was some obvious confusion with module and function.
    There are several free youtube videos and articles with examples that may be helpful.
    Spend some time with these. Make a simple function, and see how it is called.

    The code in your post #1 is not a function.

    Watch this free video by Steve Bishop, or any of the other 70 or so videos he has on MSaccess/vba

    Good luck.

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Orange,
    Thanks for the links. I am slowly going through all the video's and learning. I haven't found the answer to the original question yet. I did fins a "work around" per se as the videos alluded to another way. Under the Option Compare Database I put Option Explicit and then all my DIM lines. This placed them all outside the modules and made them available to all the modules on the form. I did this to three forms, but there are other Single send forms where the capability is required so I had to leave them on there in the module.

  7. #7
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Quote Originally Posted by Thompyt View Post
    Orange,
    Thanks for the links. I am slowly going through all the video's and learning. I haven't found the answer to the original question yet. I did fins a "work around" per se as the videos alluded to another way. Under the Option Compare Database I put Option Explicit and then all my DIM lines. This placed them all outside the modules and made them available to all the modules on the form. I did this to three forms, but there are other Single send forms where the capability is required so I had to leave them on there in the module.
    Technically, you did not put them "outside" the module. You put them at the module level, which makes them available to all the procedures in that module, be it a form/report module, standard module or class module. You have to be careful doing that - it's not a great idea to do it carte blanche. It may give them more exposure than what is necessary or safe, meaning they can be altered by other procedures without you realizing it. A form does not have several modules as you say, only one. It can have several procedures in that module.
    I haven't found the answer to the original question yet
    Ummm, my suggestion didn't even warrant a comment?

  8. #8
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Micron,
    Apologies, I did see you comment and tried it. Got more confused. I am still working on it though. I am hoping to get to it through the videos. I like the videos and it is a good resource. You and all the others have helped me very much with what I have so far. So much so I am trying to wax more and more eloquent on how I do my coding.
    Probably just digging myself deeper and deeper though LOL.

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

Similar Threads

  1. What is Module?
    By glen in forum Modules
    Replies: 1
    Last Post: 09-14-2012, 09:11 AM
  2. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  3. Module Help
    By gumbi17 in forum Modules
    Replies: 3
    Last Post: 10-20-2011, 03:38 PM
  4. Run a Module
    By mchadwick in forum Modules
    Replies: 7
    Last Post: 09-02-2011, 09:24 AM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 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