Well I need help with some code what I need Is to search a table by date by using two textboxes one for the start date and one for the end date here is the code that I have use so far:
Private Sub cmdExcel_Click()
'Excell Object
Dim rsTemp
Dim lc
Dim k
Dim sRecords
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "DSN=PASTEL"
mySQL = "Select Number,Description,Balance08 from CustomerMaster where Category=" & Val(txtSch.Text)
Set rsTemp = objConn.Execute(mySQL)
If rsTemp.EOF Then
MsgBox "Geen data"
objConn.Close
Set objConn = Nothing
End If
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
'For k = 1 To rsTemp.Fields.Count
' ExlObj.ActiveSheet.Cells(4, k).Font.Bold = True
'Next
Exlobj.Visible = True
'Import Data In Excell
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, 3, 1, 1
Next
rsTemp.MoveNext
NxtLine = NxtLine + 1
Loop
Screen.MousePointer = vbDefault
End Sub
What this code do is it connects to pastel data with odbc and then export the tables above to excel but i need this code to export the fields specified by the date in the two textboxes.
Private Sub cmdExcel_Click()
'Excell Object
Dim rsTemp
Dim lc
Dim k
Dim sRecords
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "DSN=PASTEL"
mySQL = "Select Number,Description,Balance08 from CustomerMaster where Category=" & Val(txtSch.Text)
Set rsTemp = objConn.Execute(mySQL)
If rsTemp.EOF Then
MsgBox "Geen data"
objConn.Close
Set objConn = Nothing
End If
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
'For k = 1 To rsTemp.Fields.Count
' ExlObj.ActiveSheet.Cells(4, k).Font.Bold = True
'Next
Exlobj.Visible = True
'Import Data In Excell
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, 3, 1, 1
Next
rsTemp.MoveNext
NxtLine = NxtLine + 1
Loop
Screen.MousePointer = vbDefault
End Sub
What this code do is it connects to pastel data with odbc and then export the tables above to excel but i need this code to export the fields specified by the date in the two textboxes.