Import from excel issue

here is the cide that does import from excel:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim view As NotesView

Dim row As Integer

Dim written As Integer

Dim xFilename As String



Set db = session.CurrentDatabase

Set doc = New NotesDocument(db)

Set doc = session.DocumentContext

doc.From = "ImportForm"



xFilename = "E:\Import"+".xls"



Dim Excel As Variant

Dim xlWorkbook As Variant

Dim xlSheet As Variant

Print "Connecting to Excel..."



'new

Set Excel = CreateObject("Excel.application")

Excel.Visible = False	

Set xlWorkbook = Excel.Workbooks.Open(xFileName)



Set xlWorkbook = Excel.ActiveWorkbook

Set xlsheet=xlWorkbook.ActiveSheet



'//Cycle through the rows of the Excel file, pulling the data over to Notes

Print "Starting import from Excel file..."	



Dim NumberOfRows As Long

NumberOfRows = xlSheet.UsedRange.Rows.Count



row =0

written =0

row = row +2

Set doc = db.CreateDocument

Set doc = Nothing



For row = 2 To NumberOfRows

	'If doc Is Nothing Then

	

	With xlSheet

		

		Set view = db.GetView("References") 

		Set doc = db.CreateDocument

		doc.Form = "ImportForm"

		Call doc.ComputeWithForm(False,False)

		

		doc.RN = .Cells(row,1).Value

		doc.Des = .Cells(row,2).Value

		doc.T = .Cells(row,3).Value

		doc.PC = .Cells(row,4).Value

		doc.V =.Cells(row,5).Value			

		doc.BU = .Cells(row,9).Value

		doc.SP = .Cells(row,12).Value

		

		Call doc.save(True,True)

		written = written + 1

		row = row + 1

		If row = NumberOfRows +1 Then

			Goto Done

		Else

		End If

		Print written & "records imported..."

	End With

	

	'End If

Next

Done:

Print "Disconecting from Excel..."

xlWorkBook.close False

Excel.quit

Set Excel = Nothing

Print " "

End Sub


Now, I have a view where I see all imported documents. Everythigs looks ok. But, If I use @Dblookup formula in a form that looks for values in this view, I will get an error - entry not found…

I tried to open one document in the view in the edit mode, typed anything in the empty hidden field, saved the document and the document dissapeared from the view. But than when I do @DbLookup and search for a value that was in that document, the value is found.

I wrote the problem with import probolem earlier but I didn’t get anywhere. Now I’m trying to create an agent that will cycle through the whole view, open each document in edit mode, enter whatever value in a hidden field (in this case the field is called test and the value is “test”, I 'm not sure of the purpose of this procedure but it’s the only way how to make it work)

So here is the agent, but the problem I’m having with it is, that it openes only the first document in the view. For the test purpose, I set up to open the document only 20 times. If I didn’t set this up, lotus runs out of memory and falls down.

Sub Initialize

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace	

Dim db As NotesDatabase

Dim view As NotesView



Dim varName As String	



Set db = session.CurrentDatabase

Set view = db.GetView("References")

Set doc = view.GetFirstDocument



Dim i As Integer	

i=0

'While Not(doc Is Nothing)

While i<20	

	Set nextdoc = view.GetNextDocument( doc )

	Dim uidoc As NotesUIDocument

	

	Call ws.EditDocument(True, doc)

	doc.test="test"

	

	Set uidoc = ws.CurrentDocument

	Call doc.save(True, True)		

	'Call uidoc.Save

	'Call uidoc.Close

	'Set uidoc = Nothing

	'Set doc = Nothing

	Set Statdoc = nextdoc

	i=i+1

Wend

End Sub


I am not very skilled with LotusScript yet. I was trying to search for some topics in this forum but didn’t find anything. Please, help me, this database is getting me crazy.

My questions are: Is it possible to fix the import code that there will be no agent needed.

If agent is needed, could you please help me to fix the code? The agent is suppose to cycle through the documents, open them and close. One after another. There are over 1000 documents so opening them all at once would kill the memory.

thank you very much

Robert Hakala

Subject: import from excel issue

please post your DBlookup formula. Also, what is the view selection formula for your lookup view and what value are you sorting on in the first column of the lookup view?

Subject: RE: import from excel issue

please, read my other replies above. @DbLookup formula si there.

view selection formula is done by form. nothing more. First column is sorted. First column has the value whoch is the key for the @DbLookup formula

Subject: import from excel issue

Hi Robert,

You shouldn’t really need the agent at all - I think you need to concentrate on why your lookup field isn’t working.

Are you sure you need @dblookup? If you are looking up to all values in a column, you just need @dbcolumn.

If you do need @dblookup, is the column you are looking up to sorted?

Perhaps do a view.refresh to the view you are looking up to after the import to update the contents?

See if any of this helps…

Cheers,

Andrew.

Subject: RE: import from excel issue

  1. I need to do a @DbLookup2. Column is sorted

One correction - Even if I open the document in edit mode and than save it (without changing anything), the document dissapears. But NOT REALLY dissapears. Only changes possition. There are 1000 documets so it’s hard to see where it went, but if I search for it within the view, the document is found. So they don’t really dissapears.

But why is it like that? I don’t want to go through 1000 documents manually…

Any suggestion?

thank you

Subject: RE: import from excel issue

Another observation - 1/4 of imported data have value that in the view is in the first column (which is my key for @DbLookup funcion) of sting, I mean not a number. @DbLookup based on these keys works ok. @DbLookup with numbers does not…

I have used @DbLookup formula before so I suggest I know how it works. Just in case I put here the code from one of the fileds

@If(Reference != “”; @DbLookup(“” : “NoCache” ; “” ; “References” ; @Text(Reference) ; 2);“” )

Any idea where is the problem?

Subject: RE: import from excel issue

my guess would be that when you’re doing your import from excel the field value is getting saved as a number value. The reason it works after editing and saving the doc manually is the value then gets convterted o a text value. Try converting the value of that field to Text during your import script.

Subject: RE: import from excel issue

Ok, I’m at home right now, I will try it tomorow morning at work. Thank you for your replies. I will let you know how it went.

Robert Hakala

Subject: RE: import from excel issue

The reason you are running out of memory is you are opening hundreds of documents in the front end. Update documents using the notesdocument class. Remove the following lines of code and you can update as many documents as you like.

Dim uidoc As NotesUIDocument

Call ws.EditDocument(True, doc)

You say that only 1/4 of the documents in the first column show a value. What is the formula or field you have used for this column?

Subject: RE: import from excel issue

I ment that in the view you see all documents and all values for that column. 3/4 of the values in that column are numbers, only 1/4 of the values are strings. In @DbLookup formula searching for documents that have string in that field is working ok. If that field has a number (3/4) of the documents, @DbLookup is not working.

Subject: RE: import from excel issue

@Dblookup will only find text values so for one of the documents where the look up fails check the field in the document properties. If the value is shown as 34 instead of “34” then in your code convert the value to a string as Paul suggested.

Subject: RE: import from excel issue

Hi,

Try converting number value in the view column to text in column formula e.g. @Text(Reference) and then do the @DblookUp

Hope this helps.

Regards,

Munish Kaushik

Subject: NOW ITS WORKING

Setting the value in the view to @text(filed) was working.

God, the simpliest solutions are always the hardest to find. Thank you so so much. My blood pressure got stabilized.