DLookUp function doesn't want to work with my code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tujurikkuja
    New Member
    • Apr 2012
    • 13

    DLookUp function doesn't want to work with my code

    Code:
    Private Sub Command11_Click()
    Dim strSQL As String
    Dim criteria As Integer
    Dim ete As String
    Dim row, place As Integer
    ete = Me!etenduse_nimi
    row = Me!Rida
    place = Me!number
    
    criteria = DLookup("[broneeringu_id]", "BroneeringudQ", " etenduse_nimi='" & ete & "' AND rida=" & row & " AND number=" & place & " AND Toimumisaeg=" & Me!Toimumisaeg)
    strSQL = "DELETE * FROM Broneeringud WHERE broneeringu_id=" & criteria
    DoCmd.RunSQL strSQL
    End Sub
    What seems to be the problem in the code?
    ete is string
    row is integer
    place is integer
    Me!Toimumisaeg is date/time and it has date and time in the same field. It gives run-time error 3075.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    When you have a date time field, you need to demarcate it as such by surrounding it with # symbols.

    Comment

    • tujurikkuja
      New Member
      • Apr 2012
      • 13

      #3
      Weirdly enough the code goes red and starts popping up messages about the date/time not being a date.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Then I would double check to make sure the field in the table is actually a date data type. And also check that the input is in the correct format.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          You also need to handle the situation where Me.Toimumisaeg is Null. In my suggestion I use the Date() function if this value is Null.

          Try :
          Code:
          Criteria = Format(Nz(Me.Toimumisaeg, Date()), "\#m\/d\/yyyy\#")
          Criteria = "[etenduse_nimi]='" & ete & "' AND " & _
                     "[rida]=" & row & " AND " & _
                     "[number]=" & place & " AND " & _
                     "[Toimumisaeg]=" & Criteria
          Criteria = DLookup("[broneeringu_id]", "BroneeringudQ", Criteria)

          Comment

          Working...