Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    3

    Unanswered: Help with Run-time Error 2001

    Continually get the run-time error 2001 when attempting to execute this bit of code tied to a command button on a form. The code breaks on the red line "(docmd.openquery qrybynsi) piece.

    Private Sub cmdNSI_Click()
    Dim NSIs As Long

    NSIs = DCount("NSI", "qryByNSI")

    DoCmd.OpenQuery "qryByNSI", acViewNormal, acReadOnly
    DoCmd.OpenForm "frmNSI"

    DoCmd.Close acQuery, "qryByNSI", acSaveNo

    MsgBox "" & NSIs & " found.", vbOKOnly + vbInformation, "Records Found"

    Me.txtNSI.Value = Null

    End Sub


    I perform this exact same code on a seperate command button, and it executes perfectly, so I'm not clear as to why this one isn't working. Any ideas?

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    This is a little off the point, but why are you opening the query? Unless you've cut something out, it doesn't look like it needs to be opened.
    Paul

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You know how it says "Run-time error 2001"... Is there any text/description that comes along with that? I believe your problem may be to do with the number (or order/placement) of arguments... But without a copy of Access to hand or any more information my guess is well... only a guess!
    George
    Home | Blog

  4. #4
    Join Date
    Apr 2007
    Posts
    3
    when i comment past the open query piece, i get an error stating the openfrom action was cancelled.

  5. #5
    Join Date
    Apr 2007
    Posts
    3
    georgev - nothing beyod the error unfortunately. as stated initially, this works on a spereate command, so i can only assume it's a problem with the query...?

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Run-time error could be a number of things (or so Google told me) - have you searched the help file to see what this error might be due to?
    As mentioned above
    Code:
    DoCmd.OpenQuery "qryByNSI", acViewNormal, acReadOnly
    DoCmd.OpenForm "frmNSI"
    
    DoCmd.Close acQuery, "qryByNSI", acSaveNo
    Why are you opening the query, then closing it? Does your form use that query as a record source perhaps? I don't think you need to even open or close the query, as Paul suggested above.
    George
    Home | Blog

Posting Permissions

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