Run time error 2001

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramprat
    New Member
    • Oct 2008
    • 60

    Run time error 2001

    Hi
    Sorry to keep asking questions but I keep getting a run-time error 2001 "you canceled the previous operation" error whenever the code in the Dlookup line is reached. I have a table called Alphabet_lookup that I'm simply trying to extract a letter from depending on the value of counter . I first thought that "Letter" might be a reserved word so I changed the field name and still get the same error.

    It's frustrating spending an entire afternoon on something like this. Thanks for any help.


    Splits = Val([Forms]![Splits_Form]![Number_of_Split s_Textbox])
    COUNTER = 1
    Dim ltr As String
    Do
    Do While COUNTER <= Splits

    ltr = DLookup("[LETTER]", "Alphabet_looku p", "[split_num] = Counter")
    Set db = CurrentDb
    Set rs = db.OpenRecordse t("Count_Statio ns")
    rs.AddNew
    rs("PCID") = DMax("[PCID]", "Count_Stations ") + 1
    rs("Counting_S" ) = Forms!count_sta tions_form!COUN TING_S & ltr & "-" & get_global("g_g roup")
    rs("Street") = Forms!count_sta tions_form!STRE ET
    rs("Cross_St1" ) = Forms!count_sta tions_form!CROS S_ST1
    rs("Cross_St2" ) = Forms!count_sta tions_form!CROS S_ST2
    rs("Cnty_fips" ) = Forms!count_sta tions_form!CNTY _FIPS
    rs("Status") = "add/split"
    rs("Action_Note ") = "ADD:as per SPLIT"
    rs("Creation_da te") = Date
    rs.Update
    rs.Close



    If COUNTER = Splits Then
    done = yes
    Exit Do
    End If
    COUNTER = COUNTER + 1
    Loop
    Loop Until done = yes
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    "[split_num] = Counter")

    should be

    "[split_num] = " & Counter)

    ?

    Comment

    • ramprat
      New Member
      • Oct 2008
      • 60

      #3
      Thank you Chip! That fixed it right up. You are indeed a gentleman!

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        The syntax Chip gave you is valid when the field in the Where condition is Numeric. Fields that are Text or Date require a slightly different syntax. For future reference:

        'Where EmpNameID is Numeric
        Code:
         Me.Wage = DLookup("wage", "Employees", "[NameID] = " & Me.EmpNameID)
        'Where EmpNameID is
        Code:
        Text
        Me.Wage = DLookup("Wage", "Employees" , "[NameID] = '" & Me.EmpNameID & "'")

        'For Date fields
        Code:
        DLookup("[FieldNameToReturn]", "TableName", "[CriteriaField] = #" & Me.YourDate & "#")
        This same type of syntax is also valid when using DLookUp(), DMax() DSum() and so forth.

        And to both of you, Welcome to Bytes!

        Linq ;0)>

        Comment

        Working...