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. -
-
Dim InvNum As Long
-
Dim InvRec As Long
-
ArchProgressBar.Min = 0
-
ArchProgressBar.Max = InvoiceRS.RecordCount
-
-
InvDateFrom = Format(Txt_ArchiveDateFrom.Text, "dd/mm/yyyy")
-
InvDateTill = Format(Txt_ArchiveDateTill.Text, "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"
-
OpenInvoiceArchDB (InvoiceArchSQL)
-
InvoiceRS.MoveFirst
-
InvNum = InvoiceRS.RecordCount
-
-
-
-
Do Until InvRec = InvNum
-
For InvRec = 0 To InvNum
-
-
If (InvoiceRS("Invoice_Date") >= DateValue(InvDateFrom)) And (InvoiceRS("Invoice_Date") <= DateValue(InvDateTill)) Then
-
InvoiceArchRS.AddNew
-
InvoiceArchRS("Invoice_ID") = InvoiceRS("Invoice_ID")
-
InvoiceArchRS("Invoice_Date") = InvoiceRS("Invoice_Date")
-
InvoiceArchRS("Customer_ID") = InvoiceRS("Customer_ID")
-
InvoiceArchRS("Customer_Name") = InvoiceRS("Customer_Name")
-
InvoiceArchRS.Update
-
-
-
ArchProgressBar.Value = ArchProgressBar.Value + 1
-
-
Arch_lblPercent.Caption = "Archiving " & Int(ArchProgressBar.Value * 100 / ArchProgressBar.Max) & "% Done"
-
Arch_lblPercent.Refresh
-
Lbl_ArchBarCurrentRec.Caption = "Warning! This will take some time, current record:" & ArchProgressBar.Value
-
InvoiceRS.MoveNext
-
-
Next InvRec
-
End If
-
Loop
-
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 -
-
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_Date >= " & DateValue(InvDateFrom) & ") AND (Invoice_Date <= " & DateValue(InvDateTill) & ") ORDER BY Invoice_ID ASC"
-
OpenInvoiceDB (InvoiceSQL)
-
-
-
'OR
-
-
InvoiceSQL = "SELECT * FROM Invoice WHERE (Invoice_date BETWEEN " & DateValue(InvDateFrom) & " AND " & DateValue(InvDateTill) & ") ORDER BY Invoice_ID ASC"
-
OpenInvoiceDB (InvoiceSQL)
-
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 -
-
InvoiceSQL = "Insert Into Invoice_Archive " _
-
& " Select * From Invoice " _
-
& " Where Invoice_Date BETWEEN " & InvDateFrom & " AND " & InvDateTill & ""
-
OpenInvoiceDB (InvoiceSQL)
-
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.
Mar 11 '08
16 2063
Try converting those dates into a date datatype. Something like: - SELECT *
-
FROM Invoice
-
WHERE Invoice_Date BETWEEN cast('01/01/1997' as datetime) AND cast('01/01/2007' as datetime)
-- CK
says error in syntax (missing operator) and highlights the first "as"
ck9663 2,878
Recognized Expert Specialist
Where are you running it? I tested this on a sample table with smalldatetime field and it worked.
-- CK
Where are you running it? I tested this on a sample table with smalldatetime field and it worked.
-- CK
in the query builder for access, in sql view
my Invoice_Date field in the table Invoice is date/time, format short date
Try this:
InvoiceSQL = "Insert Into Invoice_Archive " _
& " Select * From Invoice " _
& " Where Invoice_Date BETWEEN #" & InvDateFrom & "# AND #" & InvDateTill & "#"
In Access, dates must be surrounded by "#" or your date will get parsed as a division statement (1 divided by 1 divided by 2007) which returns a numeric value, which will compare the date against the numeric value of the date (dates can be cast to numbers such that 1/1/1900 12:00 AM = 1.00000).
Check to see whether BETWEEN...AND is inclusive, as well (I don't remember), and if not, use >= and <= instead.
Try this:
InvoiceSQL = "Insert Into Invoice_Archive " _
& " Select * From Invoice " _
& " Where Invoice_Date BETWEEN #" & InvDateFrom & "# AND #" & InvDateTill & "#"
In Access, dates must be surrounded by "#" or your date will get parsed as a division statement (1 divided by 1 divided by 2007) which returns a numeric value, which will compare the date against the numeric value of the date (dates can be cast to numbers such that 1/1/1900 12:00 AM = 1.00000).
Check to see whether BETWEEN...AND is inclusive, as well (I don't remember), and if not, use >= and <= instead.
HAzAHH! Ty FredSovenix the # worked perfectly :P
and yes the BETWEEN... AND inst inclusive so i used >=, <= -
-
InvoiceSQL = " Select * From Invoice " _
-
& " Where (Invoice_Date >= #" & InvDateFrom & "#) AND (Invoice_Date <= #" & InvDateTill & "#) ORDER BY Invoice_ID ASC"
-
OpenInvoiceDB (InvoiceSQL)
-
ill just add the INSERT now and try it out :D
Ok the insert works now, the last thing is that i need to delete all the records that i sent to the Invoice_Archive from the Invoice table :D
how do i go about doing this ?
Ok the insert works now, the last thing is that i need to delete all the records that i sent to the Invoice_Archive from the Invoice table :D
how do i go about doing this ?
Nvm i think i know how
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RT |
last post by:
Hello;
I'm trying to create a updates pages that I can move either to the previous
record or the next record within a recordset without having to return to the
repeating list of records after each up date.
Assuming I have done the recordset correctly, which I have and the update
records command as well here is the code I'm trying to use:
<?php
|
by: M Wells |
last post by:
Hi All,
I need to change a column value in several thousand records in a table
and output a list of the record ids of the records I've updated into
another table.
The table, however, is being used by other users via a website, so I
need to make certain that website requests don't touch on the records
I'm selecting / updating.
|
by: Matt K. |
last post by:
Hi there,
I have a form in an Access project that contains a subform which
displays the results of a query of the style "select * from
where = #a certain date#". In the main part of the form
the user can change the date, which will force a requery in the
subform to bring up records from the date selected.
My question is this... The query in the subform is a very simple one,
with only three fields being returned. In the interest of...
|
by: No Spam |
last post by:
To fellow Access 2K users:
I have run into a newbie situation where I have been assigned to
create an Access database to act as a schedule. Basically, it is a
very simple setup: the end product is an Excel like grid that needs
to have:
* The periods along the top of the grid (which are weekly periods)
* The names of the emploees along the left
* The clients in the body of the grid
|
by: Robin S. |
last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope
I've done a better job of explaining myself below.
I am trying to produce a form to add products to a table (new products).
Tables:
tblCategoryDetails
CategoryID
SpecID
| |
by: Jason |
last post by:
I have a table of 650,000 records associated to contracts. Some of
the contracts have multiple records but each contract only has one
Active Record (there might be several inactive records). There are
dates associated with each of the records (whether active or
inactive). I need to compare the dates between the active and
inactive contract records.
So far, I've created a "find duplicates query" for contract to
identify contracts that...
|
by: Sharktyyfa |
last post by:
Hi, hoping someone can help.
Access 2003, WinXP.
I have built a database that uses synchro to co-ordinate with the
mothership.
All is well.
The person i built it for wants the satellites to be able to edit the
|
by: shriil |
last post by:
Hi
I have this database that calculates and stores the incentive amount
earned by employees of a particular department. Each record is
entered
by entering the Date, Shift (morn, eve, or night) and the 'employee
name'. There is another table which assigns an ID to the Shifts, i.e.
1,2 and 3 for morn, eve & night shifts respectively. From the mother
table, the incentive is calculated datewise for each employee as per
his shift duty. In...
|
by: c0l0nelFlagg |
last post by:
I have a moving dispatcher database. There are 99 drivers, 99 loaders,
and 50 different vehicles. The scheduler database is built on a 13
4 week month year so that it can be used repeatedly in any subsequent
year and recalculate the dates so that each year it is referenced to
the first available business day of any given week. This is done by
running an update query that calculates the date based on a formula
related to the month week and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |