So close...please help!

G

GL

I'm using the following code in an attempt to add
names/email addresses to a test group under my contacts
folder. I'm able to add to the contacts folder just not
the test group under it. I added a couple lines due to
someones help, and it seems right but I'm getting an error
message (Operation Failed. Object could not be found.),
so I'm thinking I'm missing something else. I don't code
as much as I should so its very possible I'm missing
something. Any suggestions would be very appreciated!!

Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim cfsub As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim Prop As Outlook.UserProperty

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
'The following line is where the error message falls
Set cfsub = cf.Folders.Item("Test")

With rst
.MoveFirst
'Loop through the records.
Do While Not .EOF

' Create a New Contact item.
Set c = ol.CreateItem(olContactItem)

'specify which outlook form to use
c.MessageClass = "IPM.Contact"

'create all built-in Outlook fields
If ![ContactName] <> " " Then c.FullName = !
[ContactName]
If ! <> " " Then c.Email1Address = ![Email]



c.Save
' c.Close

.MoveNext
Loop
End With

End Sub
 
D

Dan Artuso

Hi,
I've tested the code on my machine and it works.
Are you positively sure you have a sub-folder under your
regular contacts folder called Test?
 
G

GL

Hi Dan,
First thanks for all your efforts. In all my playing
around I had changed the folder name, BUT the problem was
it still wasn't saving to that new folder. It creates the
contact in the contacts folder. I'm thinking its because
that is what my code is telling it, but I'm not sure what
part is telling it that - I was assuming that if I pointed
to that folder that is were it would save to. I'm sorry
to keep bugging you, but I can't figure it out! Thanks!
Gina
-----Original Message-----
Hi,
I've tested the code on my machine and it works.
Are you positively sure you have a sub-folder under your
regular contacts folder called Test?

--
HTH
Dan Artuso, Access MVP


I'm using the following code in an attempt to add
names/email addresses to a test group under my contacts
folder. I'm able to add to the contacts folder just not
the test group under it. I added a couple lines due to
someones help, and it seems right but I'm getting an error
message (Operation Failed. Object could not be found.),
so I'm thinking I'm missing something else. I don't code
as much as I should so its very possible I'm missing
something. Any suggestions would be very appreciated!!

Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim cfsub As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim Prop As Outlook.UserProperty

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
'The following line is where the error message falls
Set cfsub = cf.Folders.Item("Test")

With rst
.MoveFirst
'Loop through the records.
Do While Not .EOF

' Create a New Contact item.
Set c = ol.CreateItem(olContactItem)

'specify which outlook form to use
c.MessageClass = "IPM.Contact"

'create all built-in Outlook fields
If ![ContactName] <> " " Then c.FullName = !
[ContactName]
If ! <> " " Then c.Email1Address = ! [Email]



c.Save
' c.Close

.MoveNext
Loop
End With

End Sub
[/QUOTE]


.
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top