Type Mismatch

Hello All - I am trying to create a script that will export every calendar entry to a sql db.

I get a type mismatch on the qry. SQL line.

Is this because the Subject is not Declared properly?

Sub Initialize

Dim con As New ODBCConnection

Dim qry As New ODBCQuery

Dim Session As NotesSession     

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim StartDateTime As NotesDateTime 	

Dim EndDateTime As NotesDateTime 	

Dim AppointmentType As Variant

Dim xxLocation As Variant		

Dim xxChair As Variant

Dim xxRoom As Variant 

Dim Subject As String



Set Session =  New NotesSession

Set db = session.CurrentDatabase

Set View = db.GetView("Calendar")

Set doc = view.GetFirstDocument



If con.ConnectTo("PORTAL", "ID", "Password")  Then 

	Set qry.Connection = con

	

	Do While Not(doc Is Nothing)

		Const NotesMacro1$ = "@Name([Abbreviate];@Subset(Room;1))"

		Const NotesMacro2$ = "@Name([CN];Chair)"

		

		AppointmentType = doc.getItemValue("AppointmentType")

		

		xxRoom = doc.getItemValue("Room")

		xxLocation  = doc.getItemValue("Location")

		xxChair = doc.getItemValue("Chair")

		

		If AppointmentType<>"3" Then

		Else

			xxRoom = "Room: " & Evaluate(NotesMacro1$, doc)

		End If

		

		If Location <> "" Then

			xxLocation = "Location: " & doc.Location

		Else

			xxLocation = ""

		End If

		

		If AppointmentType = "3" Then

			xxChair = "Chair: " & Evaluate(NotesMacro2$, doc)

		Elseif TaskType = "2" Then

			xxChair = "Owner: " & Evaluate(NotesMacro2$, doc)

		End If

		

		Const NotesMacro3$ = "@Trim(Subject : xxRoom : xxLocation : xxChair)"

		

		Subject = Evaluate(NotesMacro3$, doc)

		Set StartDateTime = doc.getItemValue("StartDateTime")

		Set EndDateTime = doc.getItemValue("EndDateTime")

		

		Messagebox (Subject)    

	'Messagebox (qry.sql)      

		

		qry.SQL = "insert into Portal (StartDateTime,EndDateTime,Subject) values ('" & StartDateTime &"','" & EndDateTime &"','" & Subject &"')"  

				

		Set result.Query = qry

		If Not result.Execute() Then

			Messagebox ("Error!" &  "Insert Failed")

		End If	

		

		Set doc=view.getNextDocument(doc)

	Loop

	

	Status = con.Disconnect

Else

	

	Messagebox("Could not connect to server")

End If

End Sub

Subject: Type Mismatch

StartDateTime and EndDateTime are notesdatetimes - you can’t use these directly in a string (which your qry.sql line is creating)

Use StartDateTime.DateOnly to get a string

Dan