CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    philippines
    Posts
    8

    Help Whats wrong with my code?

    Hi to all VB experts!

    i'm a newbie in VB. I have this problem regrading dateformat. can i use the format function inside a query?? i dont know whats wrong with my code. it returns an error message "too few parameters. Expected1".

    The code gets the user inputs "months.text" and "year.text" and gets the records that are equal to the month and year of the date field.

    The date field format is mm/dd/yyyy and the user inputs the month with mmm format (i'm using a combo box. user can choose whether he/she wants to view the data with the month Jan, Feb, and so on.)

    Please help me with my dilemma.

    Thanks in advance!!

    CODE:

    Data1.RecordSource = "Select publisher, address, postalcode, tel, fax, isbn, publication, author, edition, l_used, b_used From isbn Where datepart('mmm', #" & Format(Date, "mmm-dd-yyyy") & "#) = " & months.Text & " AND datepart('yyyy',date) = " & year.Text & " "
    Data1.Refresh

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    How about this one..
    Data1.RecordSource = "Select publisher, address, postalcode, tel, fax, isbn, publication, author, edition, l_used, b_used From isbn Where Format([Date], ""mmm"") = '" & months.Text & "' AND format([Date], ""yyyy"") = '" & year.Text & "'"
    Busy

  3. #3
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569
    Kjcarrots,

    I am not familiar with DATEPART, so that may be the problem.

    I have always used the SQL commands YEAR and MONTH, to achieve what you are trying to do.

    Purhaps you could try using those instead.

    (P.S. MONTH gives the months number ie 1, 2 .. 12, but there is also MONTHNAME, which give the name of the month. *DUH* )
    Mike

  4. #4
    Join Date
    May 2003
    Location
    philippines
    Posts
    8

    Thanks it worked!!!!

    Thanks guys!! it worked!! woohoo!!

    *jumps with delight*

    Joy

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured