Connecting Tech Pros Worldwide Help | Site Map

Can I change the following code?

Member
 
Join Date: Nov 2006
Posts: 98
#1: Feb 2 '07
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
Expand|Select|Wrap|Line Numbers
  1. 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
#2: Feb 2 '07

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
    Expand|Select|Wrap|Line Numbers
    1. rs.Open "select * from Table where DateField Between #" & _
    2.         strStartDate & "# AND #" & strEndDate & "#", con
  • Both
    Expand|Select|Wrap|Line Numbers
    1. rs.Open "select * from Table where empid = '" & Text1.Text & _
    2.         "' AND DateField Between #" & strStartDate & "# AND #" & _
    3.         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
#3: Feb 2 '07

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
#4: Feb 2 '07

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
#5: Feb 5 '07

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
    Expand|Select|Wrap|Line Numbers
    1. rs.Open "select * from Table where DateField Between #" & _
    2.         strStartDate & "# AND #" & strEndDate & "#", con
  • Both
    Expand|Select|Wrap|Line Numbers
    1. rs.Open "select * from Table where empid = '" & Text1.Text & _
    2.         "' AND DateField Between #" & strStartDate & "# AND #" & _
    3.         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
#6: Feb 5 '07

re: Can I change the following code?


i thing there is no error in the above query

replace the code with this one
Expand|Select|Wrap|Line Numbers
  1. rs.Open "select * from Table where empid = '" & Text1.Text & _
  2.         "' AND DateField Between #" & strStartDate & "# AND #" & _
  3.         strEndDate & "#", con,adOpenForwardOnly ,adLockReadOnly
Member
 
Join Date: Nov 2006
Posts: 98
#7: Feb 5 '07

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

Expand|Select|Wrap|Line Numbers
  1. rs.Open "select * from Table where empid = '" & Text1.Text & _
  2.         "' AND DateField Between #" & strStartDate & "# AND #" & _
  3.         strEndDate & "#", con,adOpenForwardOnly ,adLockReadOnly

I used two text boxes to get the date from the MonthView control.
So i have written the code is
Expand|Select|Wrap|Line Numbers
  1. 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
#8: Feb 5 '07

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
#9: Feb 6 '07

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.
Expand|Select|Wrap|Line Numbers
  1. rs3.Open "select * from tbl where empid = '" & Text1.Text & "' AND dat Between #" & Text2.Text & "# AND #" & Text3.Text & "#", con, adOpenForwardOnly, adLockReadOnly
  2. rs.MoveFirst
  3. Do Until rs.EOF
  4.    j = j + 1
  5.    lv.ListItems.Add j, , j
  6.    lv.ListItems(j).SubItems(1) = rs!empid
  7.    lv.ListItems(j).SubItems(2) = rs1!firstname & rs1!lastname
  8.    lv.ListItems(j).SubItems(3) = rs3!dat
  9.    lv.ListItems(j).SubItems(4) = rs3!intime
  10.    lv.ListItems(j).SubItems(5) = rs3!outtime   
  11.    rs.MoveNext
  12. 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
#10: Feb 6 '07

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
#11: Feb 6 '07

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
#12: Feb 6 '07

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.
Expand|Select|Wrap|Line Numbers
  1. rs3.Open "select * from tbl where empid = '" & Text1.Text & "' AND dat Between #" & Text2.Text & "# AND #" & Text3.Text & "#", con, adOpenForwardOnly, adLockReadOnly
  2. rs3.MoveFirst
  3. Do Until rs3.EOF
  4. j = j + 1
  5. lv.ListItems.Add j, , j
  6. lv.ListItems(j).SubItems(1) = rs!empid
  7. lv.ListItems(j).SubItems(2) = rs1!firstname & rs1!lastname
  8. lv.ListItems(j).SubItems(3) = rs3!dat
  9. lv.ListItems(j).SubItems(4) = rs3!intime
  10. lv.ListItems(j).SubItems(5) = rs3!outtime
  11. rs3.MoveNext
  12. 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.
Reply