storing monthyear in the same field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rekhasc
    New Member
    • Oct 2007
    • 66

    storing monthyear in the same field

    how to store the month and year in the same field in the database using a query....i have a query which stores current month and year in the different fields.... but i want to store in the form october2007 or 10/2007

    [code=vb]
    Private Sub cmdAdd_Click()

    Dim m As String
    Dim y As String
    Dim d As Date

    d = Now()
    m = MonthName(Month (Now))
    y = Year(Now)

    With AConn
    .ConnectionStri ng = "Provider=Micro soft.jet.OLEDB. 4.0;Data Source=E:\Graph \Graph\xpence.m db"
    .Open
    End With
    sSQL = "INSERT INTO Table1(TodayDat e,MonthName,Yea rValues,Amount, Description) " & _
    " Values (# " & Format(d, "dd/mm/yyyy") & " #,' " & m & " ',' " & y & " ', ' " & Text3.Text & " ', ' " & Text2.Text & " ') "

    AConn.BeginTran s
    AConn.Execute sSQL
    AConn.CommitTra ns
    AConn.Close

    End Sub
    [/code]

    this is the query ...what changes should made to obtain monthyear form......

    using vb6.0 and backend is access
    Last edited by debasisdas; Oct 17 '07, 09:31 AM. Reason: Formatted using code tags.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Just concatenate M and Y and store into a single character field.

    For that you need to change your table also.
    Last edited by Killer42; Oct 17 '07, 10:16 AM.

    Comment

    • rekhasc
      New Member
      • Oct 2007
      • 66

      #3
      Originally posted by debasisdas
      Just concatenate M and Y and store into a single character field.

      For that you need to change your table also.
      I am not getting ... how to concatenate m & y
      Last edited by Killer42; Oct 17 '07, 10:17 AM.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        This query should work for Access:

        "Select Format(DateFiel d,'MMM-YYYY') As MonthYear, Sum(Amt) From
        MyTable Group By Format(DateFiel d,'MMM-YYYY') "

        Regards
        Veena
        Last edited by Killer42; Oct 17 '07, 10:17 AM.

        Comment

        • GayathriP
          New Member
          • Oct 2007
          • 17

          #5
          You have to just concatenate the month and year as m & "\" & y. But your database should be restructured to store the value.

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            Originally posted by rekhasc
            I am not getting ... how to concatenate m & y
            [CODE=vb]Dim m As String
            Dim y As String
            Dim d As Date
            Dim my As String

            d = Now()
            m = MonthName(Month (Now))
            y = Year(Now)

            my = m & y[/CODE]
            Last edited by Killer42; Oct 17 '07, 10:18 AM.

            Comment

            Working...