coding issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pfm721
    New Member
    • Jun 2008
    • 8

    coding issue

    Form frmInfo with a subform frmAppointment. I want to check to see that all appointments have a complete date before I allow the user to check complete on a check box on the main form. My code (which was written by someone else) is as follows. I am getting error 2001 you canceled the previous operation. I am unable to figure out why. The references are all correct. If anyone can see whats wrong and help me with it, it would be greatly appreciated.
    Code:
    Private Sub Complete_BeforeUpdate(Cancel As Integer)
    Dim varIncompleteProject As Variant
       varIncompleteProject = (DLookup("[AppID]", "tblAppointment", _
       "[ConsultNumber]= """ & Me.ConsultNumber & _
       """ And[CompletedDate] Is Null"))
     If Not IsNull(varIncompleteProject) Then
        MsgBox "Appointment " & varIncompleteProject & " Is Not Competed"
        Cancel = True
     End If
    
    End Sub
    Last edited by NeoPa; Jul 9 '08, 01:53 PM. Reason: Please use the [CODE] tags provided
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    Try:
    Code:
    varIncompleteProject = DLookup("[AppID]", "tblAppointment", _
    "[ConsultNumber]= '" & Me.ConsultNumber & _
    "' And IsNull([CompletedDate])")
    ...If [ConsultNumber] is a Text field.
    Last edited by NeoPa; Jul 9 '08, 01:55 PM. Reason: Please use the [CODE] tags provided

    Comment

    • pfm721
      New Member
      • Jun 2008
      • 8

      #3
      Almost there I think, no I am getting a syntax error. The code now reads
      Code:
      Dim varIncompleteProject As Variant
          varIncompleteProject = DLookup("[AppID]", "tblAppointment", _
          "[ConsultNumber]= " & Me.ConsultNumber & _
          "' And IsNull[CompletedDate]")
        If Not IsNull(varIncompleteProject) Then
          MsgBox "Appointment " & varIncompleteProject & " Is Not Competed"
          Cancel = True
        End If
      Now the error is 3075
      Syntax error in strintg in query expression '[ConsultNumer]= 1234567'
      And IsNull[CompletedDate]'.

      with 1234567 being the consult number and yes consult number is a text field.

      Thanks
      Last edited by NeoPa; Jul 9 '08, 01:55 PM. Reason: Please use the [CODE] tags provided

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Hi. You are so nearly correct now. When referring to string literals, use single quotes to enclose the string value:...
        Code:
        "[ConsultNumber]= '" & Me.ConsultNumber & "'" _
        -Stewart

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32645

          #5
          Check out Quotes (') and Double-Quotes (") - Where and When to use them.

          Comment

          Working...