By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,375 Members | 3,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,375 IT Pros & Developers. It's quick & easy.

Problems with copying sample codes (MS Access)

P: 21
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
Expand|Select|Wrap|Line Numbers
  1.  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
Jan 2 '07 #1
Share this Question
Share on Google+
4 Replies


pks00
Expert 100+
P: 280
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.Application

set outApp = New Outlook.Application


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("Outlook.Application")


There is a slight overhead with late binding, but not one that is noticable nowadays.
Jan 2 '07 #2

pks00
Expert 100+
P: 280
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 :)
Jan 2 '07 #3

P: 21
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.Application

Set objOutlook = New Outlook.Application

Thanks

Anthea
Jan 2 '07 #4

P: 21
Managed to get this working, so thanks for your help!
Jan 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.