Hi, How to fix that?
runtime error 2501 openform action was canceled
runtime error 2501 openform action was canceled
Code:
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)
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