hay ocasiones en la que necesitaras saber si un informe fue impreso o visualizado en vista previa, para permitir que otra accion sea realizada. para determinar esto, puedes llamar a la siguiente funcion desde el evento onclose del informe. ??sta regresara un valor true si el reporte fue visualizado en vista previa, y un valor false si el informe fue impreso; en este ultimo caso el informe llamara a un segundo sub-procedimiento que establece una variable a nivel modulo para actuar como un indicador (flag) y tomar o no una accion. el unico truco para usar este codigo es que debes eliminar los botones para imprimir tanto de la barra de herramientas como del menu, ya que si el usuario hace una vista previa del informe y entonces imprime desde asta, la funcion aun regresara un valor de true private declare function getwindowtext _ lib "user32" alias "getwindowtexta" _ (byval hwnd&, byval lpstrtitlebuff$, _ byval intcharstocopy%) as long private declare function getclassname _ lib "user32" alias "getclassnamea" _ (byval hwnd as long, byval lpclassname as string, _ byval nmaxcount as long) as long private declare function getwindow _ lib "user32" (byval hwnd as long, _ byval wflag as long) as long private declare function findwindowex _ lib "user32" alias "findwindowexa" _ (byval hwndparent as long, byval hwndchid as long, _ byval lpclassname as string, _ byval lpwindowname as string) as long private declare function iswindowvisible lib _ "user32" (byval hwndtarget as long) as long public function chkpreview(rptname as string) as boolean ------------------------------------------------------- purpose: to see if an access report is open in preview or not (i.e. its opened to print) accepts: report name up to 100 characters return: true if in preview, false if not copyright ?? 1997-98 attac consulting group, ann arbor, mi usa all rights reserved. --------------------------------------------------------- on error goto err_mwc dim winhwnd&, hwndmidi&, hwndtarget& dim clsnamebuff$ dim clsbuffsz% dim titlebuff as string * 100 dim titlestr$ dim dwreturn& const target_window_midi = "mdiclient" const target_window_db = "oreport" const gw_hwndnext = 2 const gw_child = 5 clsbuffsz = 30 clsnamebuff = space(clsbuffsz) chkpreview = false winhwnd = application.hwndaccessapp hwndmidi = findwindowex(winhwnd, 0&, target_window_midi, vbnullstring) if hwndmidi = 0 then if its not found exit gracefully exit function end if found the midi client class, now find the oreport class window by looking through children for a report with the like name. hwndtarget = getwindow(hwndmidi, gw_child) while hwndtarget > 0 dwreturn = getclassname(hwndtarget, clsnamebuff, clsbuffsz) if instr(clsnamebuff, target_window_db) > 0 then dwreturn = getwindowtext(hwndtarget, titlebuff, 100) titlestr = trim(titlebuff) if instr(titlestr, rptname) > 0 then dwreturn = iswindowvisible(hwndtarget) if dwreturn = 1 then chkpreview = true exit function end if end if hwndtarget = getwindow(hwndtarget, gw_hwndnext) wend exit_mwc: exit function err_mwc: resume exit_mwc end function. |