ok i think this question should go here seeming its more based around SQl code rather than the vb code.
Heres my problem i have a program in vb6 with a acees backend, the table "Invoice" in the Db has about 38500 records 9 and will go up)which seems to be over the limit that a vb data grid can display. As when i view the data grid it starts out invoice_Id 84 rather than 1, but that is now fixed as i just did an Order BY ASC so thats ok
The problem is i want to archive all the invoices with the "Invoice_Da te" less than or greater than two dates a user inputs eg 01/01/1997 -> 01/01/2007 in dd/mm/yyyy format
i have tried many different ways of doing this and one that works is my using a loop and searching each record if its invoice_date matches the criteria.
[CODE=Vb]
Dim InvNum As Long
Dim InvRec As Long
ArchProgressBar .Min = 0
ArchProgressBar .Max = InvoiceRS.Recor dCount
InvDateFrom = Format(Txt_Arch iveDateFrom.Tex t, "dd/mm/yyyy")
InvDateTill = Format(Txt_Arch iveDateTill.Tex t, "dd/mm/yyyy")
InvoiceSQL = "SELECT * FROM Invoice WHERE Invoice_Date >= 01/01/1996 ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
InvoiceArchSQL = "SELECT * FROM Invoice_Archive "
OpenInvoiceArch DB (InvoiceArchSQL )
InvoiceRS.MoveF irst
InvNum = InvoiceRS.Recor dCount
Do Until InvRec = InvNum
For InvRec = 0 To InvNum
If (InvoiceRS("Inv oice_Date") >= DateValue(InvDa teFrom)) And (InvoiceRS("Inv oice_Date") <= DateValue(InvDa teTill)) Then
InvoiceArchRS.A ddNew
InvoiceArchRS(" Invoice_ID") = InvoiceRS("Invo ice_ID")
InvoiceArchRS(" Invoice_Date") = InvoiceRS("Invo ice_Date")
InvoiceArchRS(" Customer_ID") = InvoiceRS("Cust omer_ID")
InvoiceArchRS(" Customer_Name") = InvoiceRS("Cust omer_Name")
InvoiceArchRS.U pdate
ArchProgressBar .Value = ArchProgressBar .Value + 1
Arch_lblPercent .Caption = "Archiving " & Int(ArchProgres sBar.Value * 100 / ArchProgressBar .Max) & "% Done"
Arch_lblPercent .Refresh
Lbl_ArchBarCurr entRec.Caption = "Warning! This will take some time, current record:" & ArchProgressBar .Value
InvoiceRS.MoveN ext
Next InvRec
End If
Loop
[/CODE]
this is very long-winded and im sure can be done must faster with a SQl statement so this is what i came up with
[CODE=Vb]
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_Date >= " & DateValue(InvDa teFrom) & ") AND (Invoice_Date <= " & DateValue(InvDa teTill) & ") ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
'OR
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_date BETWEEN " & DateValue(InvDa teFrom) & " AND " & DateValue(InvDa teTill) & ") ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
[/CODE]
These both produce a recordcount of 0
but there is deffinatly records that meet that critria.
I also found a way so use INSERT INTO
such as
[CODE=Vb]
InvoiceSQL = "Insert Into Invoice_Archive " _
& " Select * From Invoice " _
& " Where Invoice_Date BETWEEN " & InvDateFrom & " AND " & InvDateTill & ""
OpenInvoiceDB (InvoiceSQL)
[/CODE]
But this time the code runs but doesnt actually move anything :S
So can someone give me a few pointers or correct my code plz :P
Thx in advance.
Heres my problem i have a program in vb6 with a acees backend, the table "Invoice" in the Db has about 38500 records 9 and will go up)which seems to be over the limit that a vb data grid can display. As when i view the data grid it starts out invoice_Id 84 rather than 1, but that is now fixed as i just did an Order BY ASC so thats ok
The problem is i want to archive all the invoices with the "Invoice_Da te" less than or greater than two dates a user inputs eg 01/01/1997 -> 01/01/2007 in dd/mm/yyyy format
i have tried many different ways of doing this and one that works is my using a loop and searching each record if its invoice_date matches the criteria.
[CODE=Vb]
Dim InvNum As Long
Dim InvRec As Long
ArchProgressBar .Min = 0
ArchProgressBar .Max = InvoiceRS.Recor dCount
InvDateFrom = Format(Txt_Arch iveDateFrom.Tex t, "dd/mm/yyyy")
InvDateTill = Format(Txt_Arch iveDateTill.Tex t, "dd/mm/yyyy")
InvoiceSQL = "SELECT * FROM Invoice WHERE Invoice_Date >= 01/01/1996 ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
InvoiceArchSQL = "SELECT * FROM Invoice_Archive "
OpenInvoiceArch DB (InvoiceArchSQL )
InvoiceRS.MoveF irst
InvNum = InvoiceRS.Recor dCount
Do Until InvRec = InvNum
For InvRec = 0 To InvNum
If (InvoiceRS("Inv oice_Date") >= DateValue(InvDa teFrom)) And (InvoiceRS("Inv oice_Date") <= DateValue(InvDa teTill)) Then
InvoiceArchRS.A ddNew
InvoiceArchRS(" Invoice_ID") = InvoiceRS("Invo ice_ID")
InvoiceArchRS(" Invoice_Date") = InvoiceRS("Invo ice_Date")
InvoiceArchRS(" Customer_ID") = InvoiceRS("Cust omer_ID")
InvoiceArchRS(" Customer_Name") = InvoiceRS("Cust omer_Name")
InvoiceArchRS.U pdate
ArchProgressBar .Value = ArchProgressBar .Value + 1
Arch_lblPercent .Caption = "Archiving " & Int(ArchProgres sBar.Value * 100 / ArchProgressBar .Max) & "% Done"
Arch_lblPercent .Refresh
Lbl_ArchBarCurr entRec.Caption = "Warning! This will take some time, current record:" & ArchProgressBar .Value
InvoiceRS.MoveN ext
Next InvRec
End If
Loop
[/CODE]
this is very long-winded and im sure can be done must faster with a SQl statement so this is what i came up with
[CODE=Vb]
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_Date >= " & DateValue(InvDa teFrom) & ") AND (Invoice_Date <= " & DateValue(InvDa teTill) & ") ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
'OR
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_date BETWEEN " & DateValue(InvDa teFrom) & " AND " & DateValue(InvDa teTill) & ") ORDER BY Invoice_ID ASC"
OpenInvoiceDB (InvoiceSQL)
[/CODE]
These both produce a recordcount of 0
but there is deffinatly records that meet that critria.
I also found a way so use INSERT INTO
such as
[CODE=Vb]
InvoiceSQL = "Insert Into Invoice_Archive " _
& " Select * From Invoice " _
& " Where Invoice_Date BETWEEN " & InvDateFrom & " AND " & InvDateTill & ""
OpenInvoiceDB (InvoiceSQL)
[/CODE]
But this time the code runs but doesnt actually move anything :S
So can someone give me a few pointers or correct my code plz :P
Thx in advance.
Comment