|
-
Oct 4th, 2000, 02:22 PM
#1
Thread Starter
Hyperactive Member
I've got 2 masked edit boxes (mask = ##/##/####) i want the user to be able to input the dates and have it select all dates between and including the user inputted from my database
I can get it to work if i put the dates directly into the SELECT statement but not having any luck otherwise
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 03:23 PM
#2
Hyperactive Member
If I understand what you are trying to do this may help. Get your input from the text boxes as variables, convert them, and insert them into your sql statement
dim date1 as string
dim date2 as string
date1 = text1.text 'your starting date
date2 = text2.text 'your ending date
sqlstring = "select * from mytable where date between " & format(date, date1) " and " & format(date, date2)
Hope this helps.
-
Oct 4th, 2000, 03:55 PM
#3
Thread Starter
Hyperactive Member
I've been trying something similiar to that and end up getting no records returned, but with your code i'm at least not getting an error so it's a start...
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 04:10 PM
#4
Hyperactive Member
PJB Can you show me what your code looks like. I'd like to help if I can!
-
Oct 4th, 2000, 04:18 PM
#5
Thread Starter
Hyperactive Member
this code is what i'm using to dynamically set up different reports, as i say if i put the actual dates in my SQL statement it works fine, the mask on the masked edit boxes is ##/##/#### and in my database the PayDate field is set to short date
Code:
Private Sub cmdPrint_Click()
Dim DateFrom As String
Dim DateTo As String
DateFrom = mskFrom.Text
DateTo = mskTo.Text
sqlstring = "Select * from GEService Where PayDate Between " & Format(Date, DateFrom) & " and " & Format(Date, DateTo) & ""
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = sqlstring
.Execute
End With
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open cmd
End With
Dim q As Integer
Dim intCtrl As Integer
Dim x As Integer
Dim z As Integer
x = 0
q = 0
z = 0
With DataReport6
Set .DataSource = rs
.DataMember = ""
With .Sections("Section1").Controls
For intCtrl = 1 To .Count
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs.Fields(q).Name & " :"
q = q + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = rs(z).Name
z = z + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
Unload Me
End Sub
thanks for the help you've already given
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 04:27 PM
#6
Hyperactive Member
Private Sub cmdPrint_Click()
Dim DateFrom As string
Dim DateTo As String
DateFrom = mskFrom.Text
DateTo = mskTo.Text
sqlstring = "Select * from GEService Where PayDate
*********
try adding tick marks before and after your dates
Between '" & Format(Date, DateFrom) & "' and '" &
Format(Date, DateTo) & "'"
*********
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = sqlstring
.Execute
End With
-
Oct 4th, 2000, 04:31 PM
#7
Hyperactive Member
One more thing.....
I was wrong to tell you to change the format to date. Since you are passing the value to a string you don't need to. Your code should look like this:
Private Sub cmdPrint_Click()
Dim DateFrom As String
Dim DateTo As String
DateFrom = mskFrom.Text
DateTo = mskTo.Text
sqlstring = "Select * from GEService Where PayDate Between '" & DateFrom & "' and '" & DateTo & "'"
try debug.print on sqlstring to see if you are getting a valid sql statement. I tried it and it works for me.
-
Oct 4th, 2000, 04:37 PM
#8
Thread Starter
Hyperactive Member
that gives me an error that says "data type mismatch in criteria expression"
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 04:41 PM
#9
Hyperactive Member
Did you add the tick marks before and after the dates??
sqlstring = "Select * from GEService Where PayDate Between '" & DateFrom & "' and '" & DateTo & "'"
Just out of curiousity, what database are you extracting the data from?
-
Oct 4th, 2000, 04:52 PM
#10
Thread Starter
Hyperactive Member
yup i put the tick marks in, it's a Access 97 database the data type for this field is set to Date/Time and the format is set to shortdate
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 05:04 PM
#11
Hyperactive Member
Hello PJB
If you haven't lost faith in me or found the answer yourself I think I've figured out what my problem was.
I had the format statement hosed up.
try this:
Dim DateFrom As String
Dim DateTo As String
DateFrom = mskFrom.Text
DateTo = mskTo.Text
sqlstring = "Select * from GEService Where PayDate Between '" & Format(DateFrom, "mm/dd/yy") & "' and '" & Format(DateTo, "mm/dd/yy") & "'"
You do still need the tick marks if you run this statement in SQL Server. Also you can substitute another date format if you require (i.e. "dd-mmm-yy")
-
Oct 4th, 2000, 05:36 PM
#12
Thread Starter
Hyperactive Member
with th tick marks it gives me the same dat type mismatch and without it gives me a blank form
I tried this
Code:
Select * From GEService Where Paydate Between #01/01/2000# And #12/25/2002#
and it works alright
i just tried changing my statement to
Code:
Dim DateFrom As String
Dim DateTo As String
DateFrom = mskFrom.Text
DateTo = mskTo.Text
sqlstring = "Select * from GEService Where PayDate Between '" & FormatDateTime(DateFrom, "mm/dd/yyyy") & "' and '" & FormatDateTime(DateTo, "mm/dd/yyyy") & "'"
and i just get an error that says Type Mismatch
[Edited by PJB on 10-04-2000 at 06:39 PM]
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 05:46 PM
#13
Hyperactive Member
Don't know what to say
I'm sorry...I'm fresh out of ideas. Maybe there is someone who has more experience with Access that could help. All the changes work for me (I set my field data type to shortdate and tried to run it).
Hope you find an answer.
-
Oct 4th, 2000, 05:48 PM
#14
Thread Starter
Hyperactive Member
Thanx for everything, I'm sure I'll find out it's some other stupid setting that i have wrong
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 05:49 PM
#15
Hyperactive Member
I guess I'm not out of ideas after all.
Try this:
Replace your tick marks with pound signs
sqlstring = "Select * from GEService Where PayDate Between #" & Format(DateFrom, "mm/dd/yyyy") & "# and #" &
Format(DateTo, "mm/dd/yyyy") & "#"
Give it a shot...what have you got to lose but more socks
[Edited by barrk on 10-04-2000 at 06:57 PM]
-
Oct 4th, 2000, 05:56 PM
#16
Thread Starter
Hyperactive Member
Have already tried that and got the error that said:
Run-time Error '13'
Type Mismatch
think i'll just set the computer on fire
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 05:58 PM
#17
Hyperactive Member
Why don't we just call it quits. Stop looking for socks and have a beer. Gotta go till tomorrow
-
Oct 4th, 2000, 06:00 PM
#18
Thread Starter
Hyperactive Member
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 4th, 2000, 07:45 PM
#19
Frenzied Member
The Way to do this is as follows
code
Datefrom = Cdate("your date string)
Dateto = Cdate("Your Dateto String")
.....("Select * From ???? Where MYDATE > #" & Datefrom & "# AND < #" & Dateto & "#;")
/code
Any Question Feel Free To contact me at [email protected]
-
Oct 4th, 2000, 09:12 PM
#20
Thread Starter
Hyperactive Member
For anyone interested this is what i finally got to work:
Code:
Dim DateFrom As String
Dim DateTo As String
DateFrom = CDate(mskFrom.Text)
DateTo = CDate(mskTo.Text)
sqlstring = "Select * from GEService Where PayDate Between #" & DateFrom & "# and #" & DateTo & "#"
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = sqlstring
.Execute
End With
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open cmd
End With
Dim q As Integer
Dim intCtrl As Integer
Dim x As Integer
Dim z As Integer
x = 0
q = 0
z = 0
With DataReport6
Set .DataSource = rs
.DataMember = ""
With .Sections("Section1").Controls
For intCtrl = 1 To .Count
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs.Fields(q).Name & " :"
q = q + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = rs(z).Name
z = z + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
Unload Me
End Sub
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Oct 5th, 2000, 10:32 AM
#21
Hyperactive Member
YEAH!!!!!!!!
Glad to see you got it working! Sorry I couldn't solve it for you...got you close though.
-
Oct 5th, 2000, 10:39 AM
#22
Thread Starter
Hyperactive Member
Your help was greatly appreciated barrk!!!!
VB6.0 SP4
Windows 2000
I'm thinking of a number between
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
|