Question : Callback function error in On Action of a toolbar command

I'm getting the error "Microsoft Access can't run the macro or callback function 'PrintOp'". I originally had the function in a macro and converted it to vba. It worked initially, but now I'm getting the error.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Function PrintOp() As PrintOp
On Error GoTo PrintOp_Err

    DoCmd.RunCommand acCmdPrint


PrintOp_Exit:
    Exit Function

PrintOp_Err:
    If Err.Number = 2501 Then
    Err.Clear
    Resume PrintOp_Exit
    End If
End Function

Answer : Callback function error in On Action of a toolbar command

Try changing it to a Sub procedure and remove the return value.  That works for me, though it actually opens the Print dialog, not the Print menu.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Public Sub Test()

On Error GoTo ErrorHandler

   DoCmd.RunCommand acCmdPrint
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   If Err.Number = 2501 Then
      Resume ErrorHandlerExit
   Else
      MsgBox "Error No: " & Err.Number _
         & " in Test procedure; " _
         & "Description: " & Err.Description
      Resume ErrorHandlerExit
   End If
   
End Sub
Random Solutions  
 
programming4us programming4us