|
-
Dec 8th, 2012, 04:03 AM
#1
Thread Starter
Member
[RESOLVED] Problem in monthly records.
good day! im trying to search records between 2 dates (monthly,weekly). what is wrong with my query/code?
<code>
paramDate1 = CDate(DateFrom)
paramDate2 = CDate(DateTo)
Set rs = New ADODB.Recordset
rs.Open "Select * from tblEvents where EventDate between #" & paramDate1 & "# AND #" & paramDate2 & "#", cn, 3, 2
</code>
it didn't display monthly record but can display individual date (e.g records dated 12/1/2012 but not 12/1/2012 to 12/31/2012). can u pls give me some advice? or am i doing something wrong?
thanks guys.
-
Dec 8th, 2012, 06:36 AM
#2
Hyperactive Member
Re: Problem in monthly records.
Hello, Could you please do something like below:
Code:
rs.Open "Select * from tblEvents where EventDate between " & "#" & paramDate1 & "#" & " AND " & "#" & paramDate2 & "#", cn, 3, 2
-
Dec 8th, 2012, 07:00 AM
#3
Re: Problem in monthly records.
The method shown in post #2 will not be any different.
What database are you using?
-
Dec 8th, 2012, 08:21 AM
#4
Hyperactive Member
Re: Problem in monthly records.
@ Master Guru DataMiser.. you totally right. If he use DTpicker instead assuming using Access DB, like below because i'm using DTPIcker format mm/dd/yyyy and work fine when i show Data between two Date..
Code:
S_Date = DTPicker1.Value
E_Date = DTPicker2.Value
rs.Open "Select * from tblEvents where EventDate between " & "#" & S_Date & "#" & " AND " & "#" & E_Date & "#", cn, 3, 2
-
Dec 8th, 2012, 08:38 AM
#5
Re: Problem in monthly records.
The dates must be formated as follows:
Access: #yyyy-mm-dd#
SQL: 'yyyymmdd'
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Dec 8th, 2012, 11:26 AM
#6
Re: Problem in monthly records.
As has often been suggested on this and other forums,
you must use Command with parameters, it avoids all the problems of formatting,
which as you know can be different depending on the type of database.
Database - Why should I use Parameters instead of putting values into my SQL string?
http://www.vbforums.com/showthread.php?t=548787
See also sample projects on my sign (both ADODB and ADO.NET)
-
Dec 9th, 2012, 10:55 PM
#7
Thread Starter
Member
Re: Problem in monthly records.
Hi! Im using Access 2003 as a database. Mr. brss i tried ur query but i still didn't get the correct records. BTW, what f i change the field type in my table from text to date/time? will it help? .
-
Dec 9th, 2012, 11:13 PM
#8
Hyperactive Member
Re: Problem in monthly records.
Well my friend, I'm sorry for not helping you out, I will try my best here. I think your problem related to your saved format in your DB. Have you checked your Date field format, How it's behave? This problem happend to me long time ago when i call Excel report between two date msgbox "No data found" while i have lot of data! try to use DTPicker with field Date/Time. Wish you the best. Thank you
Edited: DTPicker format will behave as your System date format. And you can customized it for sure.
Last edited by brss; Dec 9th, 2012 at 11:18 PM.
-
Dec 10th, 2012, 01:28 AM
#9
Thread Starter
Member
Re: Problem in monthly records.
whew! i finally managed to do it. for those who got same problem revise ur queries like this
Code:
("Select * from tblEvents where Eventdate >= #" & firstMonth & "# AND EventDate <= #" & lastMonth & "#")
just make sure the field in ur DB is a Date/Time formatted as "mm/dd/yyyy". Thanks a lot guys! This forum is really helpful. Cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|