|
-
June 26th, 2001, 10:34 AM
#1
Does Anyone Know Why? Ratings up for Grabs!!
My program is a contact organizer. The first time I logon to a workstation or even a PC it comes up with an error, after ending the program after the error it runs perfectly. It also runs perfectly if I open Outlook 97 before using the program. How do I get rid of that annoying problem?? This is urgent and I will give ratings.
-
June 26th, 2001, 10:36 AM
#2
Re: Does Anyone Know Why? Ratings up for Grabs!!
What is the exact error you are getting? If it is on a certain line of code, could you post the code as well? what exactly are you doing when you get this error?
-
June 26th, 2001, 10:36 AM
#3
Re: Does Anyone Know Why? Ratings up for Grabs!!
what is the error message you get?
-
June 26th, 2001, 11:01 AM
#4
Re: Does Anyone Know Why? Ratings up for Grabs!!
thanks for the quick reply!
hope you can help
I get the error in my create sub where I try to create a contact. it happens when the I try to move the object to the folder. here is my code and the error message is:
Method 'Move' of object '_DcontactItem' failed
Runtime Error '-2147417851 (80010105)'
Private Sub cmdCreate_Click()
On Err GoTo errorHandler
'Create an instance of Outlook
Set objApp = CreateObject("Outlook.Application")
'Make objContact a Conact Item in this instance of Outlook
Set objContact = _
objApp.CreateItem(olContactItem)
'Create a namespace within Outlook so that I can access folders
Set objNameSpace = objApp.GetNamespace("MAPI")
'set the folder to a public folder "VF Contacts"
Set objFolder = objNameSpace.Folders("Public Folders").Folders("All Public Folders").Folders("TIAS Public Folders").Folders("North America").Folders("United States").Folders("STR - Strathroy").Folders("VF Administration").Folders("VF Contacts")
'go through each contact in the database
For Each objItem In objFolder.Items
'check to see if company names are the same
If txtComName.Text = objItem Then
'Display a message box telling the user of the identical contact already in the database
MsgBox "There is already a contact by that name in the Database!", , "Vari-Form"
Exit Sub
End If
Next objItem
'Attribute all the fields of the form to a spot in the contact form
With objContact
.CompanyName = txtComName.Text
.BusinessAddressStreet = txtBusStreet.Text
.BusinessAddressCity = txtBusCity.Text
.BusinessAddressState = txtBusState.Text
.BusinessAddressCountry = txtBusCountry.Text
.BusinessAddressPostalCode = txtBusPC.Text
.BusinessTelephoneNumber = txtBusPhone.Text
.OtherFaxNumber = txtBusFax.Text
.FirstName = txtConFName.Text
.LastName = txtConLName.Text
.MobileTelephoneNumber = txtEmail.Text
.Home2TelephoneNumber = txtWSIB.Text
.HomeTelephoneNumber = txtInsurLiab.Text
.TelexNumber = txtAttachS.Text
.Department = txtAttachE.Text
'Move them to the public folder
.Move objFolder
End With
'Reset the Instance of Outlook to nothing
Set objContact = Nothing
Set objApp = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
'Display that Contact was created
intQValu = MsgBox("Contact Created!", , "Vari-Form")
'Ask User to Add another Contact or to continue
intQValu = MsgBox("Create Another Contact?", _
vbYesNo + vbQuestion, "Response Required")
'if user press yes
If intQValu = vbYes Then
'call main form load to start program over again
txtComName.SetFocus
Call Form_Load
Else
'Display main menu
Unload frmCreate
frmMainMenu.Visible = True
'Reset the Instance of Outlook to nothing
Set objApp = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set objContact = Nothing
End If
Exit Sub
'Reset the Instance of Outlook to nothing
Set objApp = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set objContact = Nothing
'exit sub to avoid error handler from running if everything is ok till here
Exit Sub
'error handler for any errors that occur
errorHandler:
'return a messsage box with error number and description
intQValu = MsgBox(Err.Number & " " & Err.Description, , "Vari-Form")
Err.Clear
'set variables to nothing
Set objApp = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set objContact = Nothing
Call Form_Load
Resume Next
End Sub
-
June 26th, 2001, 11:24 AM
#5
Re: Does Anyone Know Why? Ratings up for Grabs!!
I am not very good with opening outlook through VB, but I will give your problem a shot. The code all looks pretty good, with one exception. Take a look at your "with" code:
With objContact
.CompanyName = txtComName.Text
.BusinessAddressStreet = txtBusStreet.Text
.BusinessAddressCity = txtBusCity.Text
.BusinessAddressState = txtBusState.Text
.BusinessAddressCountry = txtBusCountry.Text
.BusinessAddressPostalCode = txtBusPC.Text
.BusinessTelephoneNumber = txtBusPhone.Text
.OtherFaxNumber = txtBusFax.Text
.FirstName = txtConFName.Text
.LastName = txtConLName.Text
.MobileTelephoneNumber = txtEmail.Text
.Home2TelephoneNumber = txtWSIB.Text
.HomeTelephoneNumber = txtInsurLiab.Text
.TelexNumber = txtAttachS.Text
.Department = txtAttachE.Text
'Move them to the public folder
.Move objFolder
End With
It appears that you are trying to move the objContact to the database in the with statement at
the same time you are trying to set up the variables in the with statement. Take the line .Move objFolder
out of the with statement, and place it after the end with. Like this:
With objContact
.CompanyName = txtComName.Text
.BusinessAddressStreet = txtBusStreet.Text
.BusinessAddressCity = txtBusCity.Text
.BusinessAddressState = txtBusState.Text
.BusinessAddressCountry = txtBusCountry.Text
.BusinessAddressPostalCode = txtBusPC.Text
.BusinessTelephoneNumber = txtBusPhone.Text
.OtherFaxNumber = txtBusFax.Text
.FirstName = txtConFName.Text
.LastName = txtConLName.Text
.MobileTelephoneNumber = txtEmail.Text
.Home2TelephoneNumber = txtWSIB.Text
.HomeTelephoneNumber = txtInsurLiab.Text
.TelexNumber = txtAttachS.Text
.Department = txtAttachE.Text
End With
objContact.Move objFolder
That is about all the help I can be. If you are still having problems after this, I can only
say that I hope you get the answer you are looking for.
Spectre5000
-
June 26th, 2001, 11:44 AM
#6
Re: Does Anyone Know Why? Ratings up for Grabs!!
The only thing I can think of is that the public folders aren't initialsed when you first access them here...perhaps see if
Debug.print objFolder.Name
works immediatelybefore your with block.
HTH,
D.
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
-
June 26th, 2001, 12:18 PM
#7
Re: Does Anyone Know Why? Ratings up for Grabs!!
Thanks for the suggestions! My folder is intialized and I still get the error with the .move method outside the with but both were very good ideas,
God Bless,
Dream out loud
Bonovox011
-
June 26th, 2001, 03:47 PM
#8
Re: Does Anyone Know Why? Ratings up for Grabs!!
Ok, don't laugh at me for this but, I copied you code, changed a few things so it would work with a dummy form, and everything worked fine. Now for the question. Do you have permissions to write to that folder? I am not an exchange expert, but it seems to me that the adminstrator, should have the ability to limit who can write to a specific public folder.
Only thing I can think of for the moment.
Hope this helps.
-
June 27th, 2001, 06:13 AM
#9
Re: Does Anyone Know Why? Ratings up for Grabs!!
Just a thought.
If it works when you have Outlook already opened then perhaps you need to logon to the mapi session in your code.
objapp.Session.Logon 'Whatever profile'
-
June 27th, 2001, 07:34 AM
#10
Re: Does Anyone Know Why? Ratings up for Grabs!!
That still didn't do the trick but I appreciate your suggestion. Looks like I just might have stumped the gurus on this one. I'm still scratching my head if anyone else might have an idea please post it
God Bless,
Dream Out Loud
Bonovox011
-
July 3rd, 2001, 10:37 AM
#11
Re: Does Anyone Know Why? Ratings up for Grabs!!
I'm replying to my own message to tell you all thank you and what I did to fix the problem. Since it would work when Outlook was running I simply used the GetExplorer method before running the create contact code and it works beautifully now.
Thanks and God Bless,
Dream Out Loud
Bonovox011
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|