Results 1 to 5 of 5
  1. #1
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Using Right in VBA

    I need to concatenate an invoice Id with the last two digits of a date field (invoice date) to get the invoiceid & Year (otherwise I'll have 60000 invoice id's ). I can't seem to figure out the best way to do this within a recordset. here is the code I am using.

    ......
    CustId = rs.Fields("companyId")
    InvNoYr = rs.Fields("ItemDate")
    Here is where I am trying to get the two digit year (91, 92 etc)

    Inv

    'right( [tblInvoiceDetails]![InvoiceDate] ,2)

    Do While rs.EOF = False

    If rs.Fields("companyId") = CustId Then



    rs.Edit
    rs!InvoiceId = InvNo & InvNoYr -
    Here is where I need to join the invoiceNo to the Invoice Year
    rs.Update
    rs.MoveNext

    .....

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    If that's a date/time field, try

    Format(Year(rs.Fields("ItemDate")), "yy")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    Your code gave me a number 5 for the variable. So I changed to code InvNoYr = Right((rs.Fields("ItemDate")), "2") and got the year 91. Thanks for the help.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Just curious... what's the issue with 60000 invoice numbers, especially if each invoice has a Customer Number and an Invoice Date (or equivalent)?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I goofed it, should simply be the Format function. I'm guessing your field is text though, which changes everything.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums