Results 1 to 4 of 4
  1. #1
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25

    RST Findfirst date problem

    Hi,
    I am trying to count number of days between dates and check a table of holidays at the same time. Trouble is the Findfirst is not finding dates in the table. Dates in the table and on the form are entered using calendar control 11.0. All date fields are set to short date with input mask 99/00/000;0;_

    Can anyone see what I am doing wrong???

    Thanks
    Colin


    Private Sub Command44_Click()
    On Error GoTo Err_Command44_Click

    Dim intCount, intPublic As Integer
    Dim rst As DAO.Recordset
    Dim DB As DAO.Database

    Set DB = CurrentDb
    Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tbHolidays", dbOpenSnapshot)

    'StartDate = StartDate + 1
    'To count StartDate as the 1st day comment out the line above

    intCount = 0
    intPublic = 0
    Do While strStartDate <= strEndDate
    rst.FindFirst "[HolidayDate] = #" & strStartDate & "#"
    If rst.NoMatch Then
    intCount = intCount + 1
    Else
    intPublic = intPublic + 1
    End If
    strStartDate = strStartDate + 1
    Loop

    Exit_Command44_Click:


    Text42 = intCount
    txPublic = intPublic
    rst.Close
    Set rst = Nothing
    Set DB = Nothing
    Exit Sub

    Err_Command44_Click:
    MsgBox Err.Description
    Resume Exit_Command44_Click

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I see this thread is marked as Solved. Is it, and will you post your solution so others can benefit?

  3. #3
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25

    Thumbs up

    Had to set date format by putting "Const strJetDate = "\#mm\/dd\/yyyy\#" in the header section of the code and then altered the code as follows. Now works like a charm.

    Code:
    Private Sub coDaysCalc_Click()
       On Error GoTo Err_coDaysCalc_Click
       Dim intCount, intPublic As Integer
       Dim tbHolidays As DAO.Database
       Dim rst As DAO.Recordset
       Dim strLookDate As String
       Set tbHolidays = CurrentDb
       Set rst = tbHolidays.OpenRecordset("SELECT [HolidayDate] FROM tbHolidays", dbOpenDynaset)
       'strStartDate = strStartDate + 1
       'To count StartDate as the 1st day comment out the line above
       intCount = 0
       intPublic = 0
       strLookDate = Format(strStartDate, strJetDate)
       Do While strStartDate <= strEndDate
          rst.FindFirst "[HolidayDate] = " & strLookDate & ""
          If rst.NoMatch Then
             intCount = intCount + 1
          Else
             intPublic = intPublic + 1
          End If
          strStartDate = strStartDate + 1
          strLookDate = Format(strStartDate, strJetDate)
       Loop
    Exit_coDaysCalc_Click:
       txDaysApplied = intCount - txRDO
       txPublic = intPublic
       rst.Close
       Set rst = Nothing
       Set tbHolidays = Nothing
       Exit Sub
    Err_coDaysCalc_Click:
       MsgBox Err.Description
       Resume Exit_coDaysCalc_Click
    End Sub
    Sorry can't seem to get the code to indent properly here to make it easier to read.
    Last edited by RuralGuy; 08-09-2010 at 07:27 AM. Reason: Added code tags

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thank you very much for your solution.

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

Similar Threads

  1. Recordset Findfirst Problem
    By ColPat in forum Programming
    Replies: 6
    Last Post: 07-22-2010, 04:34 AM
  2. Problem With Date
    By jlg759 in forum Programming
    Replies: 6
    Last Post: 07-02-2010, 12:40 PM
  3. Problem with date when importing
    By ds_8805 in forum Import/Export Data
    Replies: 5
    Last Post: 01-27-2010, 02:30 AM
  4. Date Problem
    By oldteddybear in forum Queries
    Replies: 1
    Last Post: 08-30-2009, 08:52 AM
  5. Problem with date field...
    By Rameez in forum Access
    Replies: 9
    Last Post: 06-23-2009, 10:29 AM

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