troubleshooting Question

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

Avatar of masmatc
masmatc asked on
Lotus IBMMicrosoft ExcelScripting Languages
8 Comments1 Solution2619 ViewsLast Modified:
Hi there,

working on a Notes 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 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 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
		Goto cancel 
	End If 
	ado.ConnectionString = strConn
	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"
				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	
			End If
			Print "Processing "+Cstr(rowTotal) +" of "+Cstr(total) + " in Sheet Name " + Cstr(sheetName(count))
			rowTotal = rowTotal + 1
	Call ws.ViewRefresh
	Messagebox "Excel File successfully imported." , 0, "Messagebox"
	Print "Done importing"
	Exit Sub
	Messagebox "Error" & Str(Err) & ": " & Error$
	Exit Sub
End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros