Results 1 to 5 of 5

Thread: Help Plz

  1. #1
    Join Date
    Jan 2005
    Posts
    45
    Rep Power
    0

    Default Help Plz

    i'm working on a project. i am supposed to list the data in a datagrid for a corresponding month or year. i used a datepicker to add the date to the database. so the data is entered in a short date format. so i wouold like to retrieve the month section from the date saved and run a query to find the entry for the corresponding month. any help would be greatly accepted.

  2. #2
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by Denjam View Post
    i'm working on a project. i am supposed to list the data in a datagrid for a corresponding month or year. i used a datepicker to add the date to the database. so the data is entered in a short date format. so i wouold like to retrieve the month section from the date saved and run a query to find the entry for the corresponding month. any help would be greatly accepted.
    To retrieve the month portion of a date do something like (use the month() function:
    Code:
     
     Dim varMonth,varDate
     varDate=#1/2/2009#
     varMonth=month(varDate)
     msgbox varMonth
    You can use the month() function in a query like this:
    Code:
     
     Dim strSQL 
     strSQL="SELECT Table1.someDateField " & _
                " FROM Table1 " & _
                 " WHERE Month([someDateField])=4;"
    Please note that the month function returns an integer corresponding to the month. Therefore april is 4
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  3. #3
    Join Date
    Jan 2005
    Posts
    45
    Rep Power
    0

    Default

    Thanks but that didn't work, i want to use the datepart function but it is given me errors. the error states that no parameter set.
    sqlstr="SELECT Lecturer.LastName, Items.ItemName, Assignments.Date_of_Request
    FROM Lecturer INNER JOIN (Items INNER JOIN Assignments ON Items.ItemCode = Assignments.ItemCode) ON Lecturer.LectId = Assignments.LectID where datepart("m",date_of_request)"= & 4
    i keep getting errors can you please help me out.

  4. #4
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by Denjam View Post
    Thanks but that didn't work, i want to use the datepart function but it is given me errors. the error states that no parameter set.
    sqlstr="SELECT Lecturer.LastName, Items.ItemName, Assignments.Date_of_Request
    FROM Lecturer INNER JOIN (Items INNER JOIN Assignments ON Items.ItemCode = Assignments.ItemCode) ON Lecturer.LectId = Assignments.LectID where datepart("m",date_of_request)"= & 4
    i keep getting errors can you please help me out.

    This code should work (USING THE MONTH FUNCTION)
    Code:
    sqlstr="SELECT Lecturer.LastName, Items.ItemName, 
        Assignments.Date_of_Request
        FROM Lecturer INNER JOIN 
        (Items INNER JOIN Assignments ON Items.ItemCode = Assignments.ItemCode) 
        ON Lecturer.LectId = Assignments.LectID
        WHERE ((Month([date_of_request])=4));"

    This code should also work (USING THE DATEPART FUNCTION)
    Code:
    sqlstr="SELECT Lecturer.LastName, Items.ItemName, 
        Assignments.Date_of_Request
        FROM Lecturer INNER JOIN 
        (Items INNER JOIN Assignments ON Items.ItemCode = Assignments.ItemCode)
        ON Lecturer.LectId = Assignments.LectID
        WHERE (((DatePart("m",[date_of_request]))=4));"

    Therefore this is the SQL string that should be passed to the database:
    Code:
    sqlstr="SELECT Lecturer.LastName, Items.ItemName, " & _
        " Assignments.Date_of_Request " & _
        " FROM Lecturer INNER JOIN " & _
        " (Items INNER JOIN Assignments ON Items.ItemCode = Assignments.ItemCode) " & _
        " ON Lecturer.LectId = Assignments.LectID " & _
        " WHERE ((Month([date_of_request])=" & 4 & "));"
    Last edited by ToxXxic; Apr 15, 2009 at 10:11 AM.
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  5. #5
    Join Date
    Jan 2005
    Posts
    45
    Rep Power
    0

    Default

    thank for the response to the first question it prove to be quite helpful. thanx.
    I would like a favour i'm using visual basic 2008, i want to make some reports and print from a datagrid. can someone plz assist me with that i would be careful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •