Question

Importing Excel file into Lotus Notes...how to import the Date values correctly?

Asked by: masmatc

Hi there,

working on a Notes database...one of its function is...that user will be able to import the Excel files.

Following is the code i am using to import the Excel files into Lotus Notes database...i found this on the web and alter it a bit for my needs.

so far...as far as my testing goes it is working fine. However i am not sure that how come i am getting the correct Date values. Please allow me to explain further.

Excel file that i am using for testing...in it couple of columns have Date values (i have set the format for all the cells in these columns as Date). And then using the code below...importing the Excel file in the Lotus Notes Db. And along with other values...getting the correct Date values from the Excel file. Even when i change the cell format of the Date  e.g. (13-Dec-07 or  September 19, 2008 or  11/26/08) i got the correct Date values in the Lotus Notes Db. i think what i am saying is that how the code below knows what is the month and what is the day from different cell formats that i have in the Excel file. The one thing that i found that even if i have different cell formats e.g. (13-Dec-07 or September 19, 2008 or 11/26/08) in the formula bar of the Excel it always shows as mm/dd/yyyy (is this is due to the control panel -> regional setting? and is this is why even with different cell formats i am getting the correct date values?)

what i like to make sure is this that when user will use the Lotus Notes Db and import their generated Excel files, how to ensure that the code below import the correct Date values
from the user Excel files. (like what if user does not format the column and its cells as Date, what if in the user Excel file the Date value stored as text or something). i do not know how?...may be some kind of check in the following code to make sure that the Date Values from Excel files will be imported correctly.

Following are the lines from the code below...where i am reading it from the Excel and storing it in the Date fields on the form.

cur_doc.Datefield1 = rs.Fields(8).value  
cur_doc.Datefield2 = rs.Fields(9).value

Sorry if it seems like a long story but i like to give as much related info as i can. Need your help.

Sub Click(Source As Button)
	
	On Error Goto errorHandler
	
	Dim ses As New notessession 
	Dim ws As New notesuiworkspace 
	Dim cur_db As notesdatabase 
	Dim cur_doc As notesdocument
	Dim sheetName(0) As String 
	
	' variables to check for the duplicate records
	
	Dim dc As notesdocumentcollection
	Dim ClaimNum As String
	Dim VINum As String
	Dim formula As String 
		
	Set cur_db = ses.currentdatabase 
	Set ado = createobject("ADODB.Connection")
	Set rs = createobject("ADODB.Recordset")
	
	FileName = ws.OpenFileDialog( False , "Select Excel Sheet" , , "C:\") ' hardcode the path where excel sheet resides.
	
	If Isarray(fileName) Then
		sFileName = Cstr(fileName(0))
		strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
           ' if excel sheet has no header column then set HDR = No
	Else
		Goto cancel 
	End If 
	
	ado.ConnectionString = strConn
	ado.Open
	
	sheetName(0) = "Sheet1$" ' if excel sheet has more sheets to process then increase the array and assign it with sheet name
	Dim count As Integer 
	Dim nCounter As Integer
	
	For count = Lbound(sheetName) To Ubound(sheetName)
		Set rs = ado.Execute("select count(*) from [" + sheetName(count) + "]") 
		total = rs.fields(0).value
		Set rs = ado.Execute("select * from [" + sheetName(count) + "]") 
		rowTotal = 1 
		While Not rs.EOF
			flag = True
			Set cur_doc = cur_db.createdocument
			cur_doc.form = "frm1"
			
			
			'to check for the duplicate record
			
			ClaimNum = rs.Fields(4).value   
			VINum = rs.Fields(2).value
			
			formula      =  "Form = " + Chr(34) + "frm1" + Chr(34) + " &  ClaimTX = " +  Chr(34) + ClaimNum  +  Chr(34) +  " & VINumTX = " +  Chr(34) + VINum + Chr(34) + "" 
			
			Set dc = cur_db.Search(formula, Nothing, 0)
			If dc.count > 0 Then
				
				Messagebox "A Record is already Exist.", 0, "Messagebox"
				
			Else
				
				cur_doc.field1 = rs.Fields(0).value
			            cur_doc.field2 = rs.Fields(2).value
				cur_doc.field3 = rs.Fields(4).value
                                                cur_doc.Datefield1 = rs.Fields(8).value  
				cur_doc.Datefield2 = rs.Fields(9).value
			
                                      ' have removed the other fields from here	 to make the code short			
				
                                                cur_doc.FormCreatedByTX = ses.CommonUserName
				cur_doc.CrDT = Now()
				
				
			'Set the User Name in the Names field and Author in the Authors field
				Dim ItemUserName As NotesItem 
				Dim ItemAuthor As NotesItem 
				Dim AuthorName As String 
				
				AuthorName = ses.UserName 
											
				Set ItemUserName  = New NotesItem(cur_doc , "ByNA", AuthorName, NAMES)
				Set ItemAuthor  = New NotesItem(cur_doc , "authorsAN", AuthorName, AUTHORS)
				
				If cur_doc.NumTX(0) = "" Then 
					cur_doc.NumTX =  GenerateSequentialNumber ("frm1" )
				End If	
				
							
				Call cur_doc.save(True,True) 
								
			End If
			rs.MoveNext
			
			
			Print "Processing "+Cstr(rowTotal) +" of "+Cstr(total) + " in Sheet Name " + Cstr(sheetName(count))
			rowTotal = rowTotal + 1
			
		Wend
		
	Next 
	Call ws.ViewRefresh
	ado.Close
	
	Messagebox "Excel File successfully imported." , 0, "Messagebox"
	Print "Done importing"
	Exit Sub
	
errorHandler:
	Messagebox "Error" & Str(Err) & ": " & Error$
	ado.Close
	Exit Sub
	
cancel: 
	
	
End Sub

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:

Select allOpen in new window

This question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Sign Up Now!
Asked On
2009-10-27 at 08:48:31ID: 24847641
Tags

Lotus Script

,

Importing Excel

,

Lotus Notes database

Topics

Lotus Notes

,

Microsoft Excel Spreadsheet Software

,

Scripting Languages

Participating Experts
2
Points
500
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

Companies like CVS, Honeywell, Chevron, Toyoto, TriStar Pictures, the U.S. Army, and Accenture

Your Complete Technology Resource

900+ topic areas (and counting)

Related Solutions

  1. Lotus -> Excel : @roundup command
    I have changed a number of .wk4 files to .xls (XL97) format for use at work. However the Lotus files use the @roundup and @rounddown command. The new Excel file did not convert these it simply pasted the values in. However the wizard...
  2. excell an lotus
    what is the diference between lotus an excell?
  3. excel to lotus / copy paste isnot working
    I am copying some cells from Excel and want to paste to a Lotus Notes mail but characters change. When I paste my copy into a new mail it writes " Arial...,Times New Roman..." But there is no problem from Excel to Word&No...
  4. Lotus Notes
    Hi, the situation is - i have designed a questionnaire in Lotus Notes using the Lotus Dmino Designer....the problem is that i need to produce a summary of the answers for the 'sales manager'. As in i need to show how many responses per ...
Tutorials are great ways to tackle hard problems!

Featured Articles

Read through articles written by top experts!

Get full access to the help you need.

Subscribe Now

30-day free trial. Register in 60 seconds.

The Latest Technology News and Tips

Your answer is only minutes away!

New Solutions Everyday

Because of our active community of experts, on average new questions receive their first comment in under 30 minutes.

Top Lotus Notes Questions

       

Hear What our Users are Saying

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

20130221-EE-VQP-039

3 Ways to Join

30-Day Free Trial

Why Experts Exchange?

Trusted by 44 of the Top Fortune 50 Companies. Verizon, Bank of America, IBM, Windows, Dell, Target, Boeing, Comcast, AT&T

Why Experts Exchange?

The go-to tech resource for hundreds of thousands.

"With the help of Experts Exchange -- I have been able to meet my deadlines and produce effective products"

Jan Miller

"I just today started my third contract assignment which I attribute to the skills I am learning from other experts."

Robert Antonellis

"It's my sole resource as I'm kind of an MS Access loner at my company. It's like having colleagues available when I run out of my own steam."

Karen Ruskin

Why Experts Exchange?

50K Tech Experts available to help

Leew has been an expert here since 1997 and is a master at Windows 2000 and XP, hard drives/storage and Small Business Server.

lrmoore has been an expert here since 2000 and is a six-time Microsoft MVP with over 18 years experience in the networking industry.

angeliii has been an expert here since 2000 and is a Microsoft MVP for his work with MS SQL Server and Development

Why Experts Exchange?

3 Million+ Questions Solved

"The experts approach solutions with patience and innovative ideas, and ultimately I have my problem solved."

Gary Serkhoshian

"Most every situation is already posted and answered, a quick search usually gives a solution. EE is truly a bargain."

Bob Schatzman

"9 out of 10 times Experts Exchange has the accepted solution or an open discussion of the potential solutions to the problem."

Kenny Red

Why Experts Exchange?

Serving tech professionals since 1996.

At Experts Exchange, we treat each question as unique and deserving of an answer.

As one of the most enduring technology resources, our community knows the importance of helping each individual with their problem, no matter how complex or how simple. We're here to collaborate with you.

Business Account Plans