Advertisement

07.14.2008 at 08:59AM PDT, ID: 23563104
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.7

routine to insert records into table with beginning and ending dates that don't have gaps

Asked by LenTompkins in Visual Basic Programming, Access Coding/Macros

Tags: , ,

I started to write a routine that will allow the users will enter a start date and a price.  I calculate the end date by determining what  the next date is and then giving that record an end date of the next start date - 1.  
Part        Start Date      End Date     Price
123       1/1/2008         3/14/2008     13.5
123      3/15/2008        5/28/2008     13.62
123      5/29/2008        12/31/9999   13.65
If my table looks like this and if I add any new record after the beginning date of 1/1/2008 the code as I have it written works great.  My problem is when I decide to add a start date prior to the first date in the table, I am having issues.  I tried to do a DLookup and return the earliest date with a Min Function, but I get an error stating that the aggregate function in a where clause can't be in a DLookup.  
Here is the code I have:
Private Sub BegDate_BeforeUpdate(Cancel As Integer)
On Error GoTo BegDate_1
    Dim strSQL As String
    Dim PDate As Date
    Dim OldEndDate As Date
    Dim CorEndDate As Date
    Dim OldBegDate As Date
    Dim Cnt As Integer
    Cnt = 0
   
    PDate = Me.BegDate - 1
    Me.ID = Me.NO & Format(Me.BegDate, "yyyymmdd")
    DoCmd.SetWarnings (False)
    OldEndDate = DLookup("[EndDate]", "[AWPPricetbl]", "[NO]= " & Me.NO & " and #" & Me.BegDate & "# > BegDate and #" & Me.BegDate & "# < EndDate")
    If OldEndDate = #12/31/9999# Then
        strSQL = "UPDATE AWPPricetbl SET AWPPricetbl.EndDate = #" & PDate & "# WHERE (((AWPPricetbl.EndDate)=#12/31/9999#) AND ((AWPPricetbl.[NO])= " & Me.NO & "));"
        DoCmd.RunSQL strSQL
        Me.EndDate = #12/31/9999#
    Else
        CorEndDate = Me.BegDate - 1
        strSQL = "UPDATE AWPPricetbl SET AWPPricetbl.EndDate = #" & CorEndDate & "# WHERE (((AWPPricetbl.EndDate)=# " & OldEndDate & "#) AND ((AWPPricetbl.[NO])= " & Me.NO & "));"
        DoCmd.RunSQL strSQL
        Me.EndDate = OldEndDate
    End If
BegDate_Exit:
    DoCmd.SetWarnings (True)
    Exit Sub
BegDate_1:
    Cnt = Cnt + 1
    Me.EndDate = #12/31/9999#
    If Cnt = 2 Then
        Resume BegDate_Exit
    Else
        OldBegDate = DLookup("[BegDate]", "[AWPPricetbl]", "[NO]= " & Me.NO & " and Min(BegDate)")
        Me.EndDate = OldBegDate - 1
        Resume BegDate_Exit
    End If
   
End Sub
do I have to write a routine to look this up or is there another way to perform this task?Start Free Trial
 
 
[+][-]07.14.2008 at 09:34AM PDT, ID: 21999637

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, Access Coding/Macros
Tags: microsoft, Access, 2003
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.14.2008 at 10:03AM PDT, ID: 21999914

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628