Sendobject Action Canceled

  • Onderwerp starter Onderwerp starter Spelt
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

Spelt

Gebruiker
Lid geworden
4 mrt 2010
Berichten
18
Beste forumgebruikers,

ik heb veel berichten op het internet nagekeken. Nergens kon ik mijn oplossing vinden. Wellicht weet een van jullie experts het hopelijk! Ik heb namelijk een Sendobject code. Als ik op Cancel klik krijg ik de foutmelding Run-time Error 2501 - The sendobject action was cancelled. Wie zou dit stukje code aan willen passen zodat ik geen Foutmelding meer krijg vanuit Access?

Private Sub Command4_Click()
'place this code in the clicked event of your command
'button which starts the report, e.g., "Run Report"
' listbox is called List71
' the recordsource for the report is a query
' containing all the field elements you need
Dim strFilter As String
Dim varItem As Variant
Dim Answer As VbMsgBoxResult

' loop through listbox items selected
For Each varItem In Me!List5.ItemsSelected
strFilter = strFilter & "[Bak ID] = '" & _
Me![List5].ItemData(varItem) & "' OR "
Next ' continue loop
'
' the next bit of code will subtract out the last "OR"
If strFilter <> "" Then
strFilter = Left(strFilter, Len(strFilter) - 4)
Else
MsgBox "Er zijn geen bakken geselecteerd."
List5.SetFocus
Exit Sub
End If
'
' now, run the report using strFilter to pass a string
' containing the needed customers
Dim stDocName As String

DoCmd.OpenReport "Sum Reasons", acPreview, , strFilter
DoCmd.SendObject acReport, stDocName

On Error Resume Next
If Err.Number = 2501 Then
MsgBox "Cancelled"
Else
MsgBox Err.Description
End If
On Error GoTo 0
Exit Sub
End Sub

Bij voorbaat dank,

Nick Spelthan
 
Je foutroutine doet niet zoveel, omdat-ie na de fout staat, en niet ervoor. De bedoeling van het afvangen van fouten is, dat de routine 'weet' wat-ie moet doen als de fout optreedt. Dat houdt dus in, dat je eerst instelt wat er moet gebeuren. Dus iets als dit:

Code:
On Error GoTo Foutje

DoCmd.OpenReport "Sum Reasons", acPreview, , strFilter
DoCmd.SendObject acReport, stDocName

Exit Sub

Foutje:
If Err.Number = 2501 Then
     MsgBox "Cancelled"
Else
     MsgBox Err.Description
End If
End Sub
 
Hey Michel,

Alweer bedankt..Ik kom iedere keer vrij ver. Maar tis lastig om mn hoofd derbij te houden.

Gelukkig heb je alweer een probleempje opgelost:D

Hulde!
 
Mag je 'm ook nog op opgelost zetten...
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan