Problems with copying sample codes (MS Access)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • antheana
    New Member
    • Nov 2006
    • 21

    Problems with copying sample codes (MS Access)

    Hi there,

    I have a specific problem, but also wanted to guage everyone's thoughts on copying codes. For less knowledgeable people like myself, I sometimes find i difficult to write code from scratch, but now that I've been developing a database (with your help!) I'm starting to see how the code is working.

    However, I recently copied some code to create an appointment in MS Outlook and adapted it to use existing data on my job form, as opposed to having the user enter everything from scratch.

    AlthoughI adapted it, I keep getting a compile error for
    Code:
     Dim objOutlook As Outlook.Application
    When I tested it in the database example I downloaded, my amendments worked. Now that I have copied the command click code into my database I'm getting compile errors. "User defined-type not defined"

    So 2 questions:

    1. Can anyone advise me on how to fix the compile error?

    2. When copying code, do we just copy the code we see or are there other linked modules/macros etc that we should be copying as well?

    Thanks,

    Anthea
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    What u are using is the outlook activex control. What this means is if u use it this way then u have to add a reference. For any controls u use, u must add them as a reference. From vba window, u go to Tools/References and check the appropriate one (in this case Microsoft Outlook Object Library)

    Do remember with Microsoft, there controls are in different directories depending on what version office u use therefore these become broken if used with a different version.

    Using this approach is known as early binding.

    Dim outApp as Outlook.Applica tion

    set outApp = New Outlook.Applica tion


    Now I prefer to code this way so as to make use of the intellisense menu,
    However when I release change, I change it to use Late Binding

    Late binding is basically you create objects then create them, What this saves is you having to add the reference in your code so u never suffer from broken references.
    eg

    Dim outApp as Object

    set outApp = CreateObject("O utlook.Applicat ion")


    There is a slight overhead with late binding, but not one that is noticable nowadays.

    Comment

    • pks00
      Recognized Expert Contributor
      • Oct 2006
      • 280

      #3
      Anthea

      with regards to copying code, its all a learning process. You can copy a sample of code, and any additional stuff that u may need if specified.
      If it doesnt work, see where the failings are and u may find u need to add something or change some declaration etc, it is not going to be the same thing.

      In your case, its just knowing about adding references (early binding) and ive explained late binding as well, so hopefully now you understand.

      The more u work with Access, the more comfortable and experienced you will become and you will soon learn what you need to do, just takes time Im afraid.

      Good luck and Happy New Year :)

      Comment

      • antheana
        New Member
        • Nov 2006
        • 21

        #4
        Hi there,

        Thanks alot, that does make sense. One slight problem, I have NO idea where to put that first bit of code. I managed to find the references and select the Outlook option you mentioned.

        But if I am to 'bind' globally (this is what I got from your post), I wasn't sure where to put the code:

        Dim objOutlook As Outlook.Applica tion

        Set objOutlook = New Outlook.Applica tion

        Thanks

        Anthea

        Comment

        • antheana
          New Member
          • Nov 2006
          • 21

          #5
          Managed to get this working, so thanks for your help!

          Comment

          Working...