Need better solution

D

David

Hi All,
I have a little problem with my com add in and I have come up with a
solution but I feel the solution is a hack and I don't know why my solution
really works. So here is the situtation.

My com add in allows the user to poke a button, select 3 text files and
the information of the csv text files are imported into the contacts
folders. The problem is that after the first file is imported, the second
text file will produce a "applicate not-defined" error when trying to save a
changed contact. All information in the text files are valid. However if I
put a delay in between calling the import functions, then everything works
fine.

For example:
'this does NOT work
ImportFile("file1.csv")
ImportFile("file2.csv")

'this does work
ImportFile("file1.csv")
Delay 1 'delays for 1 second
ImportFile("file2.csv")


The ImportFile function looks like this

Private Sub ImportFile(strFileName As String)
On Error GoTo ProcessError

If Not strFileName = "" Then
Dim bFileOpen As Boolean
bFileOpen = False
nFileNumber = FreeFile

Open strFileName For Input As #nFileNumber
bFileOpen = True

Dim myitem As ContactItem

Dim strName As String
Dim strUserInfo1 As String
Dim strUserInfo2 As String
Dim strCurrentName As String

Do
Input #nFileNumber, strName, strUserInfo1 , strUserInfo2

'do you have a new contact or same contact?
If strCurrentName = "" Or strCurrentName <> strName Or
myitem Is Nothing Then
'new contact (objFolder is defined some where else)
Set myitem = objFolder.Items.Find("[FullName] = """ &
strName & """")
strCurrentName = strName
End If

If Not myitem Is Nothing Then
'update the dnc value for that phone number
myitem.UserProperties.item(strUserInfo1).Value =
strUserInfo2
If Not myitem.Saved Then
'THIS IS WHERE THE ERROR IS TRIGGERED
myitem.Save
End If
End If
Loop Until EOF(nFileNumber)
End If

GoTo ProcessEnd:
ProcessError:
PopupError "Importing Error"

ProcessEnd:
If bFileOpen Then
Close #nFileNumber
End If
Set myitem = Nothing
End Sub

So why does delaying make or break the myitem.Save method?

Thanks
David
 

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