This is the error i get when i search a pervasive database between to dates need help
Invalid Date,Time or Timestamp
And here is the code i Used:
Private Sub cmdSearch_Click()
Dim rsTemp
Dim lc
Dim k
Dim sRecords
'Connect To Database
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "DSN=PASTEL"
mysql = "Select CustomerCode,DocumentNumber,InclusivePrice,Qty,Description from HistoryLines " 'Where Date Between '" + txtFrom.Text + "' and '" + txtTo.Text + "'"
Set rsTemp = objConn.Execute(mysql)
'Draw Excel WorkBook With Colums
Set Exlobj = CreateObject("excel.application")
Exlobj.Workbooks.Add
Screen.MousePointer = vbHourglass
With Exlobj.ActiveSheet
' Print the heading and columns
.Cells(1, 3).Value = "Worcester Gas en Sport Maand Einde"
.Cells(1, 3).Font.Name = "Verdana"
.Cells(1, 3).Font.Bold = True:
.Cells(1, 3).Font.Size = 14:
.Cells(4, 1).Value = "Klient Nommer": .Cells(4, 2).Value = "Klient Naam"
.Cells(4, 3).Value = "Aankope Per Produk": .Cells(4, 4).Value = "Totale Aankope"
.Cells(4, 5).Value = "Totale Aankope Sonder BTW": .Cells(4, 6).Value = "Prys Per Kg"
.Cells(4, 7).Value = "Totale Wins": .Cells(4, 8).Value = "Wins Per Kg"
.Cells(4, 9).Value = "Wins Persentasie"
End With
'Import Data In Excel WorkBook
Exlobj.Visible = True
NxtLine = 5
Do Until rsTemp.EOF
For lc = 0 To rsTemp.Fields.Count - 1
' Populate data into the sheet
Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsTemp.Fields(lc)
'If rsTemp.Fields.Item(lc).Name <> "DATE" Then
' Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsTemp.Fields(lc)
'Else
' Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = Format(rsTemp.Fields(lc), "dd/mm/yy")
'End If
' Autoformat the sheet
Exlobj.ActiveCell.Worksheet.Cells(NxtLine, lc + 1).AutoFormat _
xlRangeAutoFormatList2, 0, regular, 0, 0, 0
Next
rsTemp.MoveNext
NxtLine = NxtLine + 1
Loop
Screen.MousePointer = vbDefault
End Sub
Invalid Date,Time or Timestamp
And here is the code i Used:
Private Sub cmdSearch_Click()
Dim rsTemp
Dim lc
Dim k
Dim sRecords
'Connect To Database
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "DSN=PASTEL"
mysql = "Select CustomerCode,DocumentNumber,InclusivePrice,Qty,Description from HistoryLines " 'Where Date Between '" + txtFrom.Text + "' and '" + txtTo.Text + "'"
Set rsTemp = objConn.Execute(mysql)
'Draw Excel WorkBook With Colums
Set Exlobj = CreateObject("excel.application")
Exlobj.Workbooks.Add
Screen.MousePointer = vbHourglass
With Exlobj.ActiveSheet
' Print the heading and columns
.Cells(1, 3).Value = "Worcester Gas en Sport Maand Einde"
.Cells(1, 3).Font.Name = "Verdana"
.Cells(1, 3).Font.Bold = True:
.Cells(1, 3).Font.Size = 14:
.Cells(4, 1).Value = "Klient Nommer": .Cells(4, 2).Value = "Klient Naam"
.Cells(4, 3).Value = "Aankope Per Produk": .Cells(4, 4).Value = "Totale Aankope"
.Cells(4, 5).Value = "Totale Aankope Sonder BTW": .Cells(4, 6).Value = "Prys Per Kg"
.Cells(4, 7).Value = "Totale Wins": .Cells(4, 8).Value = "Wins Per Kg"
.Cells(4, 9).Value = "Wins Persentasie"
End With
'Import Data In Excel WorkBook
Exlobj.Visible = True
NxtLine = 5
Do Until rsTemp.EOF
For lc = 0 To rsTemp.Fields.Count - 1
' Populate data into the sheet
Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsTemp.Fields(lc)
'If rsTemp.Fields.Item(lc).Name <> "DATE" Then
' Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = rsTemp.Fields(lc)
'Else
' Exlobj.ActiveSheet.Cells(NxtLine, lc + 1).Value = Format(rsTemp.Fields(lc), "dd/mm/yy")
'End If
' Autoformat the sheet
Exlobj.ActiveCell.Worksheet.Cells(NxtLine, lc + 1).AutoFormat _
xlRangeAutoFormatList2, 0, regular, 0, 0, 0
Next
rsTemp.MoveNext
NxtLine = NxtLine + 1
Loop
Screen.MousePointer = vbDefault
End Sub