[RESOLVED] Data Environment Query Problem
I've been trying to make this code work but all efforts failed
this is my code
Dim date1 As Date << also tried to make this as string but neither work
Dim date2 As Date << this also
date1 = Calendar1.Year & "/" & MonthName(Calendar1.Month) & "/" & Calendar1.Day
date2 = Calendar2.Year & "/" & MonthName(Calendar2.Month) & "/" & Calendar2.Day
one problem i know is the querying of date(bold text), when i try to remove it, the code works, but when it's there it won't work, and why is that?, i've tried a fixed query in the data environment command and it works, but i need a run time query not a fixed query
With DE1
If .rsCommand1.State = 1 Then .rsCommand1.Close
.Commands("Command1").CommandType = adCmdText
.Commands("Command1").CommandText = "SELECT [date],[time_start],[time_end],[total_time] FROM [computer_usage] WHERE ([date] BETWEEN " & date1 & " AND " & date2 & ") AND ([comp_name] = '" & Text1.Text & "') ORDER BY [date] DESC"
.Commands("Command1").Execute
.rsCommand1.Open
DataReport1.Show
End With
please somebody help me, i really really need this code to work :(
Re: Data Environment Query Problem
Your variables should be declared as String.
In terms of appending them to the query you have it almost correct, but you have missed out the delimiters.
For an explanation and examples of delimiters to use around values within SQL statements, see the article How do I use values (numbers, strings, dates) in SQL statements? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)
Re: Data Environment Query Problem
thnx now i know, i missed out the # sign in the date variable in the query