get month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • berry
    New Member
    • May 2007
    • 46

    get month

    Hi all..
    I wana to get the specific date which is in database and show in the datagrid.
    For example, I want key in the 'january' in a text box and want to get all january data. How I call it out? I'd tried but can't get it. My code is:
    Code:
    Adodc1.RecordSource = "select * from date where userDate LIKE 'txtMonth %'"
    where userData is the field name, txtMonth is the text box i key in the month.
    Please help me.
    Thanks..
  • samycbe
    New Member
    • Feb 2007
    • 83

    #2
    Dear Friend,

    Have a month list in combo and on click have an invisible text box contains month value eg jan =1 mar =3 dec =12.

    and write a code

    select * from <Table> where datepart(m,<fie ldname>) = val(txtinvmonth )

    it will work

    samy

    Originally posted by berry
    Hi all..
    I wana to get the specific date which is in database and show in the datagrid.
    For example, I want key in the 'january' in a text box and want to get all january data. How I call it out? I'd tried but can't get it. My code is:
    Code:
    Adodc1.RecordSource = "select * from date where userDate LIKE 'txtMonth %'"
    where userData is the field name, txtMonth is the text box i key in the month.
    Please help me.
    Thanks..

    Comment

    • berry
      New Member
      • May 2007
      • 46

      #3
      Originally posted by samycbe
      Dear Friend,

      Have a month list in combo and on click have an invisible text box contains month value eg jan =1 mar =3 dec =12.

      and write a code

      select * from <Table> where datepart(m,<fie ldname>) = val(txtinvmonth )

      it will work

      samy
      I write my code as:
      Code:
      Private Sub cmbMonth_Click()
      If cmbMonth.Text = "January" Then
          Text2 = 1    
      ElseIf cmbMonth.Text = "February" Then
          Text2 = 2
      ElseIf cmbMonth.Text = "March" Then
          Text2 = 3
      ElseIf cmbMonth.Text = "April" Then
          Text2 = 4
      ElseIf cmbMonth.Text = "May" Then
          Text2 = 5
      ElseIf cmbMonth.Text = "June" Then
          Text2 = 6
      ElseIf cmbMonth.Text = "July" Then
          Text2 = 7
      ElseIf cmbMonth.Text = "August" Then
          Text2 = 8
      ElseIf cmbMonth.Text = "September" Then
          Text2 = 9
      ElseIf cmbMonth.Text = "October" Then
          Text2 = 10
      ElseIf cmbMonth.Text = "November" Then
          Text2 = 11
      ElseIf cmbMonth.Text = "December" Then
          Text2 = 12
      End If
      Adodc1.RecordSource = "select * from date where datepart(month,dateNow) =  Val(Text2.Text)"
      Adodc1.Refresh
      DataGrid1.Refresh
      End Sub
      There is an error "Unkown column 'month' in 'where clause'". What's wrong there?

      Comment

      • coolminded
        New Member
        • Mar 2007
        • 137

        #4
        Originally posted by berry
        I write my code as:
        Code:
        Private Sub cmbMonth_Click()
        If cmbMonth.Text = "January" Then
            Text2 = 1    
        ElseIf cmbMonth.Text = "February" Then
            Text2 = 2
        ElseIf cmbMonth.Text = "March" Then
            Text2 = 3
        ElseIf cmbMonth.Text = "April" Then
            Text2 = 4
        ElseIf cmbMonth.Text = "May" Then
            Text2 = 5
        ElseIf cmbMonth.Text = "June" Then
            Text2 = 6
        ElseIf cmbMonth.Text = "July" Then
            Text2 = 7
        ElseIf cmbMonth.Text = "August" Then
            Text2 = 8
        ElseIf cmbMonth.Text = "September" Then
            Text2 = 9
        ElseIf cmbMonth.Text = "October" Then
            Text2 = 10
        ElseIf cmbMonth.Text = "November" Then
            Text2 = 11
        ElseIf cmbMonth.Text = "December" Then
            Text2 = 12
        End If
        Adodc1.RecordSource = "select * from date where datepart(month,dateNow) =  Val(Text2.Text)"
        Adodc1.Refresh
        DataGrid1.Refresh
        End Sub
        There is an error "Unkown column 'month' in 'where clause'". What's wrong there?

        hi berry
        in your query, just write "m" instead of month, it has to work.

        "select * from date where datepart("m",da teNow)=Val(Text 2.Text)"

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          1.add the month name to a combo.

          2.instead of combo TEXT property use LISTINDEX property.

          3.select * from tablename where to_char(datefie ld,'mm')= listindex+1


          it will work for u.

          Comment

          • nairda
            New Member
            • May 2007
            • 39

            #6
            Originally posted by berry
            Hi all..
            I wana to get the specific date which is in database and show in the datagrid.
            For example, I want key in the 'january' in a text box and want to get all january data. How I call it out? I'd tried but can't get it. My code is:
            Code:
            Adodc1.RecordSource = "select * from date where userDate LIKE 'txtMonth %'"
            where userData is the field name, txtMonth is the text box i key in the month.
            Please help me.
            Thanks..
            Hi, Berry,

            1.Add the months name in to a combo (Look for "LIST" in you combo properties)

            2. Try these code:
            Code:
            Adodc1.RecordSource =  "select * from date where userDate like ' %" & Combo.text & "%' "
            3. You can modified when the action (Calling the data) will be ran. (After you choosed/clicked the combobox, or you can make a CommandButton to trigger the action).

            I hope these would help.
            NAIRDA

            Comment

            • mailderemi
              New Member
              • Jun 2007
              • 14

              #7
              +
              these are good but I think "Month(Date )" can be used as a macro. so this makes it easyer.
              ;)

              Comment

              Working...