Solved

Update ACCESS 2010 table field based on value in another field with VBA

Posted on 2014-11-12
5
950 Views
Last Modified: 2014-11-12
I have a table with a field DealDateContract.  There are two additional fields in the table that need to be updated with information based on the date in this field, but I can't get the below to work.  Am not sure if there is a QUATER function in ACCESS 2010.  

Public Sub YearQuarterSort()
'UPdates quarter and quarter sort columns in tblReportSource table
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("tblReportSource")
With rst
rst.MoveFirst
Do While Not rst.EOF

        .Edit
            If IsDate(.DealDateContract) Then
        !YrQtr = Year(.DealDateContract) & "-Q" & Quarter(.DealDateContract)
        !YrQtrSort = Year(.DealDateContract) & "-Q" & Quarter(.DealDateContract) & .DealDateContract
        .Update

Loop
    rst.Close
    Set rst = Nothing
End With


End Sub
0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40438245
There is no Quarter function, but you can use:

    DatePart("q", .DealDateContract)

/gustav
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40438258
And you could reduce to:

     !YrQtr = Format(.DealDateContract, "yyyy\-\Qq")
     !YrQtrSort = Format(.DealDateContract, "yyyy\-\Qqmmdd")

/gustav
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40438345
Storing values that can be easily calculated in a query is poor practice not to mention violating first normal form and the second one isn't even useful since you should be sorting by the date field itself.
0
 

Author Closing Comment

by:ssmith94015
ID: 40438410
Thank you.  This is better than what I inherited.  And Yes, Pat, you are correct, but I am dealing with a legacy system and trying to do as much as I can without having to re-write the entire thing, which I do not have time to do.  I mostly am trying to get this thing to work for a six-month life cycle.  Where I can, I normalize, but sometimes the source process is so convoluted I just have to go with it!

Sandra
0
 

Author Comment

by:ssmith94015
ID: 40438431
One final comment and actually this I going to be another question on suggestions how to resolve, but rather than creating a partner table with partner names, this previous programmer put three-letter acronyms in column headers so now have to figure out how to report on partner data dynamically determining which columns to use as well as the types are not consistent so I cannot even parse out the client name and then column information.  Now the client wants to add two more partners so now I need to add columns rather than simply add their names to a partner list with associated types of business processes.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Null or "" 28 53
ORDER BY 7 40
Can someone please explain to me what value or object is needed in this code MS Access VBA. 8 47
VBA Delete sql "Too Few Parameters" 8 24
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question