Hello all,
I am getting this error when trying to open a form to listbox-specified records (I have extended selection on):
run-time error '2501':
The OpenForm action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, but
then clicked Cancel in a dialog box.
For example, you used the Close method to close a changed form, then clicked Cancel
in the dialog box that asks if you want to save the changes you made to the form.
---- code
Private Sub lstResult_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32 ' vbKeySpace key
KeyCode = 32 ' this is the "revaluation"
' that kills the escape key action
'Open frmCustomer based on the ID from lstResult listbox
Dim stDocName As String
stDocName = "frmCustomer"
Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim strList As String
strList = ""
Set frm = Forms!frmSearch
Set ctl = frm!lstResult
For Each varItm In ctl.ItemsSelected
strList = strList & "'" & ctl.ItemData(varItm) & "', "
'Debug.Print ctl.ItemData(varItm)
Next varItm
strList = Left(strList, Len(strList) - 2)
If IsLoaded("frmCustomer") = False Then
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
End If
Case Else ' just in case you want to
' take a look at the key code generated
' by other keystrokes
'MsgBox KeyCode ' comment this out when it annoys you
End Select
End Sub
----
Private Sub cmdExit_Click()
If IsLoaded("frmCustomer") = True Then
Forms!frmCustomer.RecordSource = "qdfAll"
End If
Me.SetFocus
DoCmd.Close acForm, Me.Name
End Sub
I am getting this error when trying to open a form to listbox-specified records (I have extended selection on):
run-time error '2501':
The OpenForm action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, but
then clicked Cancel in a dialog box.
For example, you used the Close method to close a changed form, then clicked Cancel
in the dialog box that asks if you want to save the changes you made to the form.
---- code
Private Sub lstResult_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32 ' vbKeySpace key
KeyCode = 32 ' this is the "revaluation"
' that kills the escape key action
'Open frmCustomer based on the ID from lstResult listbox
Dim stDocName As String
stDocName = "frmCustomer"
Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim strList As String
strList = ""
Set frm = Forms!frmSearch
Set ctl = frm!lstResult
For Each varItm In ctl.ItemsSelected
strList = strList & "'" & ctl.ItemData(varItm) & "', "
'Debug.Print ctl.ItemData(varItm)
Next varItm
strList = Left(strList, Len(strList) - 2)
If IsLoaded("frmCustomer") = False Then
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
End If
Case Else ' just in case you want to
' take a look at the key code generated
' by other keystrokes
'MsgBox KeyCode ' comment this out when it annoys you
End Select
End Sub
----
Private Sub cmdExit_Click()
If IsLoaded("frmCustomer") = True Then
Forms!frmCustomer.RecordSource = "qdfAll"
End If
Me.SetFocus
DoCmd.Close acForm, Me.Name
End Sub