Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013

    Unanswered: runtime error 2501 openform action was canceled

    Hi, How to fix that?
    runtime error 2501 openform action was canceled

    Option Compare Database
    Option Explicit
    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)
            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
    Join Date
    Apr 2004
    outside the rim
    This line: DoCmd.OpenForm "f_produkti_print" opens the form.
    The cancel occurs after this line.

    Either the user is canceling it, or there is something in the Open Event of the form that is setting Cancel = True.

    I would also look at the SQL string you are assigning to the query - it is possible the SQL statement is invalid and when the form opens, it tries the query, which fails and subsequently cancels the form from opening.

    After you assign the SQL to the query, try to open the query.
    If the query opens fine, close it and try to manually open the form.
    have fun!

    Todd S.
    click to email

    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET

    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  3. #3
    Join Date
    Apr 2013
    Hi, thanks for the answer.

    I figurate how to fix, I just remove this:


    The problam was, in SQL query, the code insert ""

    like this:


    if is only 6 is good

Posting Permissions

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