Results 1 to 3 of 3
  1. #1
    rumenrs is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Mar 2013
    Posts
    32

    runtime error 2501 openform action was canceled

    Hi,


    How to fix that: "runtime error 2501 openform action was canceled"

    Here is the code:

    Code:
    Private Sub Generate_Click()
    ' Declare variables
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim varItem As Variant
        Dim strCriteria As String
        Dim strSQL As String
    ' Get the database and stored query
        Set db = CurrentDb()
        Set qdf = db.QueryDefs("q_produkti_print")
    ' Loop through the selected items in the list box and build a text string
        If Me!list_names.ItemsSelected.Count > 0 Then
            For Each varItem In Me!list_names.ItemsSelected
                strCriteria = strCriteria & "produkti_vav.ID = " & Chr(34) _
                              & Me!list_names.ItemData(varItem) & Chr(34) & "OR "
            Next varItem
            strCriteria = Left(strCriteria, Len(strCriteria) - 3)
        Else
            strCriteria = "produkti_vav.ID Like '*'"
        End If
    ' Build the new SQL statement incorporating the string
        strSQL = "SELECT * FROM produkti_vav " & _
                 "WHERE " & strCriteria & ";"
    ' Apply the new SQL statement to the query
        qdf.SQL = strSQL
    ' Open the query
        DoCmd.OpenForm "f_produkti_print"
    ' Empty the memory
        Set db = Nothing
        Set qdf = Nothing
    End Sub

  2. #2
    Parsonshere is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2012
    Location
    Rusk
    Posts
    25
    It's hard to tell without knowing the query and table source, but it looks like you are using a listbox multi-select, here are my thoughts. Do you have a hidden key that is an autonumber or numeric. If so, you don't need the chr(34) which I believe to be the ", since number data type don't require them. My other observation is that an "where produkti_vav.ID in (1, 2, 3)" or "where produkti_vav.ID in ("Item1", "Item2", "Item3") (if it is text) would be more appropriate than the "or" where criteria statement you are building.

  3. #3
    rumenrs is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Mar 2013
    Posts
    32
    Hi,
    thanks for the answer.

    That's really help me!

    I just remove:
    Chr(34)

    and re-create the form from query
    Last edited by rumenrs; 04-11-2013 at 11:23 AM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 11-28-2012, 03:43 PM
  2. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  3. Replies: 3
    Last Post: 07-19-2012, 06:22 AM
  4. Replies: 7
    Last Post: 07-18-2012, 07:53 AM
  5. Error: The OpenReport action was canceled
    By francisdm@state.gov in forum Reports
    Replies: 1
    Last Post: 12-14-2011, 01:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums