Runtime Error 2505

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peterkennett
    New Member
    • Jan 2008
    • 12

    Runtime Error 2505

    Everything was fine in my DBase until I added one line of code:

    Me.[jobnumber] = jobnumbervariab le

    This assigns the text variable jobnumbervariab le to my Table's jobnumber text field. Now the dabase won't save the data after this field is updated!

    Here's the whole code for this sub:

    If Left(jobnumberv ariable, 3) = "ESC" Then
    me.[jobnumber] = jobnumbervariab le
    DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    end if
    end Sub


    Now I get error number 2501 and a message that my doCmd command could not be done. It errors on the DoCmd line.

    I checked the variable and it contains perfect data. I checked the table and the field [jobnumber] is ok too.

    All I want this sub to do is to save the record, but add in the new jobnumber from the variable "jobnumbervaria ble" before saving the data, as long as this variable contains valid data as checked by the IF statement.

    Does anyone know what is wrong here?

    Peter
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    My guess, and it's just a guess, because you've left out an important piece of the puzzle, is that you're trying to save a record in an event where this isn't allowed. The missing piece is the name of the sub this code resides in. My guess is that it's the Form_BeforeUpda te sub.

    If this is the case, you need to change your code around so that it doesn't save the record if the condition isn't met. Something like:

    Code:
    If Left(jobnumbervariable, 3) <> "ESC" Then
      Cancel = True  '[b]Don't save the record[/b]
       Me.FieldHoldingJobNumberVariable.SetFocus
    Else
      Me.[jobnumber] = jobnumbervariable
    end if
    If the condition is met, you assign the variable and do nothing; the record will automatically be saved without your intervention.

    But, as I say, I'm only guessing here. We really need to know what sub you have the code in.

    Linq ;0)>

    Comment

    Working...