Can I change the following code? | Member | | Join Date: Nov 2006
Posts: 98
| |
Hi everybody, I want to retrieve the details from the database by the date from (MM/DD/YYYY) to (MM/DD/YYYY). For that I have to change the following code as follows - rs.Open "select * from Table where empid='" & Text1.Text & "'", con
So kindly anyone reply me.
| | Moderator | | Join Date: Oct 2006 Location: Australia
Posts: 7,748
| | | re: Can I change the following code? Quote:
Originally Posted by sreekandan Hi everybody, I want to retrieve the details from the database by the date from (MM/DD/YYYY) to (MM/DD/YYYY). For that I have to change the following code as follows rs.Open "select * from Table where empid='" & Text1.Text & "'", con Do you need to do this instead of the empid, or the two together? Here are some ideas... - Just the date range
- rs.Open "select * from Table where DateField Between #" & _
-
strStartDate & "# AND #" & strEndDate & "#", con
- Both
- rs.Open "select * from Table where empid = '" & Text1.Text & _
-
"' AND DateField Between #" & strStartDate & "# AND #" & _
-
strEndDate & "#", con
I'm assuming here that your dates are in string variables, already formatted as MM/DD/YYYY.
| | Lives Here | | Join Date: Oct 2006
Posts: 1,626
| | | re: Can I change the following code?
And you are assuming it is an Access database
| | Moderator | | Join Date: Oct 2006 Location: Australia
Posts: 7,748
| | | re: Can I change the following code? Quote:
Originally Posted by willakawill And you are assuming it is an Access database Guilty.
I do tend to think in terms of VB6 and Access, and if people aren't specific, I figure they'll just have to make do with what they get. :)
| | Member | | Join Date: Nov 2006
Posts: 98
| | | re: Can I change the following code? Quote:
Originally Posted by Killer42 Do you need to do this instead of the empid, or the two together? Here are some ideas... - Just the date range
- rs.Open "select * from Table where DateField Between #" & _
-
strStartDate & "# AND #" & strEndDate & "#", con
- Both
- rs.Open "select * from Table where empid = '" & Text1.Text & _
-
"' AND DateField Between #" & strStartDate & "# AND #" & _
-
strEndDate & "#", con
I'm assuming here that your dates are in string variables, already formatted as MM/DD/YYYY. I tried with that codigs.But run time error has occured as "Too few parameters required".So kindly give me the suggestion for that.
| | Member | | Join Date: Jan 2007 Location: Kerala/Dubai
Posts: 85
| | | re: Can I change the following code?
i thing there is no error in the above query
replace the code with this one - rs.Open "select * from Table where empid = '" & Text1.Text & _
-
"' AND DateField Between #" & strStartDate & "# AND #" & _
-
strEndDate & "#", con,adOpenForwardOnly ,adLockReadOnly
| | Member | | Join Date: Nov 2006
Posts: 98
| | | re: Can I change the following code? Quote:
Originally Posted by sukeshchand i thing there is no error in the above query
replace the code with this one - rs.Open "select * from Table where empid = '" & Text1.Text & _
-
"' AND DateField Between #" & strStartDate & "# AND #" & _
-
strEndDate & "#", con,adOpenForwardOnly ,adLockReadOnly
I used two text boxes to get the date from the MonthView control.
So i have written the code is - rs.Open "select * from tbl where empid = '" & Text1.Text & "' AND DateField Between #" & Text2.Text & "# AND #" & Text3.Text & "#", con, adOpenForwardOnly, adLockReadOnly
Eventhough the same error has occured.So kindly reply me
| | Moderator | | Join Date: Oct 2006 Location: Australia
Posts: 7,748
| | | re: Can I change the following code?
It may be that you have not adjusted our field names to match your own. For example, I used the name DateField because I don't know what yours is called. If your field name is not DateField then you will need to change this.
If that's not the problem, we'll have to investigate further.
Note, if you're going to post an error message, make sure you copy it precisely. I suspect that "Too few parameters required" is not quite the wording Access used (though as always, I could be wrong).
| | Member | | Join Date: Nov 2006
Posts: 98
| | | re: Can I change the following code? Quote:
Originally Posted by Killer42 It may be that you have not adjusted our field names to match your own. For example, I used the name DateField because I don't know what yours is called. If your field name is not DateField then you will need to change this.
If that's not the problem, we'll have to investigate further.
Note, if you're going to post an error message, make sure you copy it precisely. I suspect that "Too few parameters required" is not quite the wording Access used (though as always, I could be wrong).
I have written the following code to retrieve and display the details into the ListView control. - rs3.Open "select * from tbl where empid = '" & Text1.Text & "' AND dat Between #" & Text2.Text & "# AND #" & Text3.Text & "#", con, adOpenForwardOnly, adLockReadOnly
-
rs.MoveFirst
-
Do Until rs.EOF
-
j = j + 1
-
lv.ListItems.Add j, , j
-
lv.ListItems(j).SubItems(1) = rs!empid
-
lv.ListItems(j).SubItems(2) = rs1!firstname & rs1!lastname
-
lv.ListItems(j).SubItems(3) = rs3!dat
-
lv.ListItems(j).SubItems(4) = rs3!intime
-
lv.ListItems(j).SubItems(5) = rs3!outtime
-
rs.MoveNext
-
Loop
But I couldnt retrieve all the details from the database table.
I could retrieve only the same data repeatedly until the EOF.For that how can I retrieve the full details from the table.So kindly reply me
| | Lives Here | | Join Date: Oct 2006
Posts: 1,626
| | | re: Can I change the following code?
When you are posting code please use code tags. Clearly you are highlighting your code and clicking on the center justify and bold buttons. Please don't do that. Click on the '#' button instead. This is the third time I have added code tags to your posts
Thanks
| | Member | | Join Date: Nov 2006
Posts: 98
| | | re: Can I change the following code? Quote:
Originally Posted by willakawill When you are posting code please use code tags. Clearly you are highlighting your code and clicking on the center justify and bold buttons. Please don't do that. Click on the '#' button instead. This is the third time I have added code tags to your posts
Thanks ok thanks.
I got the solution for that.
| | Member | | Join Date: Nov 2006
Posts: 98
| | | re: Can I change the following code? Quote:
Originally Posted by willakawill When you are posting code please use code tags. Clearly you are highlighting your code and clicking on the center justify and bold buttons. Please don't do that. Click on the '#' button instead. This is the third time I have added code tags to your posts
Thanks I can retrieve all the details from the table by using the following code. -
rs3.Open "select * from tbl where empid = '" & Text1.Text & "' AND dat Between #" & Text2.Text & "# AND #" & Text3.Text & "#", con, adOpenForwardOnly, adLockReadOnly
-
rs3.MoveFirst
-
Do Until rs3.EOF
-
j = j + 1
-
lv.ListItems.Add j, , j
-
lv.ListItems(j).SubItems(1) = rs!empid
-
lv.ListItems(j).SubItems(2) = rs1!firstname & rs1!lastname
-
lv.ListItems(j).SubItems(3) = rs3!dat
-
lv.ListItems(j).SubItems(4) = rs3!intime
-
lv.ListItems(j).SubItems(5) = rs3!outtime
-
rs3.MoveNext
-
Loop
But Now I want take the printout of what are the date listed inside the ListView control by clicking one command button.So kindly give me the suggestion for that.
|  | Similar Visual Basic 4 / 5 / 6 bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|