Consulting

Results 1 to 3 of 3

Thread: VB date error and transitioning to Case

  1. #1
    VBAX Newbie
    Joined
    Mar 2010
    Posts
    2
    Location

    VB date error and transitioning to Case

    Hey im having trouble with this bit of code. Ideally it is supposed to print the info to an excel sheet for any days that the program missed. I get trapped in an infinite loop with my Do until loop and i think that transitioning this to a case statement might make things easier.

    the code is as follows:
    [vba]
    'Prints previous dates if program not ran. Excluding weekends
    Do Until (DateAdd("d", 1, NewDate) = Date) 'Loops until current date
    'Determines if date was missed and if it is a weekend day
    If (Weekday(SentFailedLog.Fields("Date")) = (Today - 1)) Then
    isYesterday = True

    End If
    If (Weekday(SentFailedLog.Fields("Date")) = 1) Then
    isWeekend = True
    ElseIf (Weekday(SentFailedLog.Fields("Date")) = 7) Then
    isWeekend = True
    End If
    'If program missed running a day excel sheet is filled in w/ missed date
    If (isYesterday = False And isWeekend = False) Then
    'NewDate is date missed (Calculated by adding 1 to last date)
    NewDate = DateAdd("d", 1, SentFailedLog.Fields("Date"))
    With SentFailedLog
    .AddNew
    .Fields("Date") = NewDate
    .Fields("Cycle") = -35
    .Fields("Compact&Repair") = "No"
    .Fields("File Size") = File_Size_MB
    .Fields("F8") = "PROGRAM NOT RAN"
    .Update
    End With
    SentFailedLog.MoveLast
    End If
    Loop
    [/vba]
    any help with pseudo code would be awesome!
    Thanks

    Edit: VBA tags added to code. You can format your code for the forum by selecting it when posting and hitting the VBA button.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Case is euivqlent to an If statement, not a loop of any kind.

    It is somewhat difficult to see what is happening, it seems to be updating a database, but we are only seeing a bit.

    Why do you do

    NewDate = DateAdd("d", 1, SentFailedLog.Fields("Date"))

    not

    NewDate = DateAdd("d", 1, NewDate)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Mar 2010
    Posts
    2
    Location
    the loop and the transition to a case are two separate issues. I use the NewDate = DateAdd("d", 1, SentFailedLog.Fields("Date")) because the code updates an excel sheet that we use as a log. so if a day is missed you wouldnt want to use the current date you would want to use the next date after the last one in the sheet.

    The code posted should fill in any dates between when the program was last run up to the current date.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •