Results 1 to 5 of 5
  1. #1
    Paul Netzel is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    2

    DLookup problem

    Good Day; thanks in advance for any assistance.
    I am designing a scheduling database and am trying to use Dlookup in order to find out if a particular date on the form is within a pay period. I then want to display the pay period start date in the unbound field on a form that is designed to add a recordset to my main table. I keep getting a run error 13 and cannot figure out what is incorrect. I have used the # for dates and several other variations in the coding with the same result. I am trying to use this pay period start date in order to filter employees schedules processing of their request when the final schedule is approved for posting, which leads to another obstacle I am experiencing but will not address on this thread. Below is the coding for this form, everything works except calculatePPDate sub. I can provide more detail if needed. I have look through many posts on several different sites and have not been able to find an answer that addresses this proble. Thanks again in advance. Paul

    Sub CalculatePPDate()
    Dim txtPPDate As Date
    txtPPDate = DLookup("PP Start", "PayPeriod", "[txtStartDate]=> [Tables]![PayPeriod]![PP Start]" And "[txtStartDate]=< [Tables]![PayPeriod]![PP End]")
    End Sub



    'Create a sub to calculate the end date
    Sub CalculateEndDate()
    txtEndDate = txtStartDate + txtDays
    End Sub

    Sub CalculateTotalDays()
    txtTotDays = (txtEndDate - txtStartDate) + 1
    End Sub

    Private Sub txtDays_LostFocus()
    CalculateEndDate
    CalculateTotalDays
    CalculatePPDate
    End Sub


    'Call this code in the Updated event and the StartDate After_Update event
    Private Sub txtStartDate_AfterUpdate()
    CalculateEndDate
    CalculateTotalDays
    CalculatePPDate
    End Sub


    'Call this code in the Updated event and the StartDate Lost_Focus event
    Private Sub txtStartDate_LostFocus()
    CalculateEndDate
    CalculateTotalDays
    CalculatePPDate
    End Sub


    'Create a Recordset
    Private Sub cmdCreate_Click()
    Dim db As Database
    Dim rs As Recordset

    Set db = CurrentDb
    Set rs = db.OpenRecordset("CalendarT")

    'Loop through the no of days
    For i = 0 To txtDays

    rs.AddNew

    rs!Staff = txtStaff
    rs!DateEntered = txtDateEntered
    rs!EnteredBy = txtEnteredBy
    rs!StartRequestDate = txtStartDate + i
    rs!AdditionalDaysRequested = txtDays
    rs!TotalDaysRequested = txtTotDays
    rs!EndRequestDate = txtEndDate
    rs!Request = txtDescription
    rs!RequestNotes = txtNotes
    rs!Approved = txtApproved
    rs!DateApproved = txtDateApproved
    rs!Changed = txtChanged
    rs!ChangeDate = txtChangeDate
    rs!ChangedRequest = txtChangedRequest
    rs!PPDate = txtPPDate
    rs.Update

    Next i

    ' Clean Up and Close
    rs.Close
    db.Close

    Set rs = Nothing
    Set db = Nothing

    If MsgBox("Do you want to create another request?", vbYesNo + vbQuestion, "Create Request") = vbYes Then
    CalendarME
    Else
    StaffRequestForm
    End If


    End Sub

    Public Sub Msgboxcreate()

    'If MsgBox("Do you want to create another request?", vbYesNo + vbQuestion, "Create Request") = vbYes Then
    'CalendarME2
    'Else
    'StaffRequestForm2

    'End If

    End Sub



  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The AND should be *inside* the quotes as well.
    "[txtStartDate]=> [Tables]![PayPeriod]![PP Start] And [txtStartDate]=< [Tables]![PayPeriod]![PP End]")

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Variables must be outside the quote marks and concatenated into the statement - otherwise you have the literal text "txtStartDate" and not the value of txtStartDate. I presume txtStartDate is an input parameter - is this a textbox on form and is txtPPDate also textbox on form? Also, need [] when names have spaces or special characters/punctuation (underscore is exception) - advise avoiding their use. Also, need # delimiter for date input. Try BETWEEN AND operator, it is inclusive for the begin/end range values. Don't use the Tables collection reference and no need to prefix with tablename.

    Me.txtPPDate = DLookup("[PP Start]", "PayPeriod", "#" & Me.txtStartDate & "# BETWEEN [PP Start] AND [PP End]")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Paul Netzel is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    2
    Thanks Rural Guy for your suggestion, unfortunately this solution did not work, however, the solution posted by June 7 did work. I appreciate your efforts and assistance. Paul

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad to hear you got it resolved.

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

Similar Threads

  1. Dlookup problem
    By Terava in forum Access
    Replies: 5
    Last Post: 04-29-2013, 11:05 PM
  2. DLookup Problem
    By alsoto in forum Queries
    Replies: 5
    Last Post: 02-23-2012, 12:22 PM
  3. Problem with DLookup
    By MichealShinn in forum Programming
    Replies: 5
    Last Post: 01-25-2012, 09:08 AM
  4. DLookup problem
    By the_rock in forum Programming
    Replies: 3
    Last Post: 01-11-2012, 02:36 AM
  5. Using Dlookup problem
    By Lupson2011 in forum Access
    Replies: 5
    Last Post: 12-07-2011, 10:33 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