Consulting

Results 1 to 3 of 3

Thread: Solved: Error 2001 on AfterUpdate event

  1. #1

    Solved: Error 2001 on AfterUpdate event

    Hello all,

    I am having a problem with an Access database (Access XP).

    I have tables for Users (fields are UserID, FirstName, LastName, etc.) and Positions (PositionID, PositionName, PositionDesc [short for Position Description]). I also have a join table (called UserPosition) where I pull in the UserID and PositionID both set as primary keys (so I can "assign" Positions to Users).

    I have a query (called q_user_position) that pulls the data from the join table and both original tables, so that I can see all of the records in the join table (i.e., all assignments of Positions to Users), and also the FirstName, LastName, PositionDesc, etc.

    Finally, I have a form (called f_user_position). The goal for this form is to select a user from a drop-down list, and have all positions assigned to that user appear in a subform. On the form I have a drop-down list that pulls from the Users table. I have a subform based on the q_user_position query. I have assigned the following code to the AfterUpdate event for the drop-down list on the form:

    [vba]Private Sub Combo0_AfterUpdate()
    Dim strNewRecord As String
    strNewRecord = "SELECT q_user_position.Position, q_user_position.PositionDesc FROM q_user_position " _
    & " WHERE UserPosition_UserID = '" _
    & Me!Combo0.Value & "'"
    Me.q_user_position_subform.Form.RecordSource = strNewRecord
    End Sub[/vba]
    When I select a value from the drop-down list, I get an error message saying "Run-time error 2001: You canceled the previous operation." If I click Debug, the line it highlights is the last line, right above the End Sub (the one that begins Me.q_user"...).

    I can tell that the "strNewRecord = " line is functioning properly because I can see the string in the Locals window and it is right. It's just not able to assign it to the subform (if I understand correctly).

    What's wrong with my code? I have used this same exact code on other forms to do the same thing, and it works. I even copy-pasted the code from the working one into this one and changed the appropriate field names, and I still get this error.

    Thanks!

  2. #2
    OK, I attacked it from a little bit of a different angle, and it appears that it is a "Data type mismatch in criteria expression." How do I fix that? The UserPosition_UserID field is a Number.

  3. #3
    Got it. I used CLng and it is now working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •