none
How do I make the "WIA.CommonDialog" modal? RRS feed

  • Question

  • Hello:

    I don´t know why the WIA.CommonDialog goes back the parent form. I can not make it modal window.

    i have try the Api function WaitForSingleObject Lib "kernel32" but I don´t like that in the Parent´s form caption show "No respond".

    Also I have tried but the result is the same.

        Dim retval As Long
        retval = ShellEx(<picture path>, "print")
        If retval = False Then MsgBox "error"

    Could anyone please help me ´cause I can not find the solution.  

    Thanks .

    Next I show you the suborutine that call the WiA.CommonDialog........

    To open it from a click button of the parent form I have this sub:

        Dim vector As Object
        Dim dialog As Object

        Set vector = CreateObject("WIA.Vector")
        vector.Add Me!sfImagen!imgFoto.Picture

        ' create the common dialog COM object, and
        ' display the photo print wizard
        Set dialog = CreateObject("WIA.CommonDialog")
        dialog.ShowPhotoPrintingWizard vector

        Set vector = Nothing
        Set dialog = Nothing

    I can not make it modal window.

    The only thing that I want is to print a unbouded image in Access 2016.

                  
    • Edited by Ixxo09 Thursday, November 9, 2017 4:01 PM
    Thursday, November 9, 2017 3:52 PM

Answers

  • I have done it by the following way:

    Private Sub cmdImprimir_Click()

       'Declarar las variables locales
       Dim MyPicFile As String
       Dim rpt As New Report
       Dim RptName As String
       
       'Establecer la varible "MyPicFile" con el nombre de
       'la imagen a imprimir.  Aquí simplemente estamos usando
       'la función "DLookUp" para obtener la ruta completa de la Imagen,
       'en caso de estar almacenada en una tabla, sino puedes establecer
       ' esta variable como quieras.
       
       'MyPicFile = Nz(DLookup("[PicPath]", "[MyTable]", "[PicID]=" & Whatever), "")
       MyPicFile = Me!sfImagen!imgFoto.Picture
       
       'Sale de la función si la variable "MyPicFile"
       'no contiene nada (cadena vacía)
       If MyPicFile = vbNullString Then Exit Sub
       
       'Atrapa los errores...
       On Error GoTo Error_PrintPic

       'Crea un informe temporal
       Set rpt = CreateReport()
       
       'Establecer las propiedades del informe
       With rpt
          '.Visible = False
          .PictureType = 1      'Enlazada
          .PictureSizeMode = 3  'Zoom
          .Picture = MyPicFile  'Imagen a imprimir
          RptName = .Name
       End With
       
       'Imprime el informe
       DoCmd.OpenReport RptName, , , , acHidden

    Exit_PrintPic:
       On Error Resume Next
       'Cerrar el informe
       DoCmd.Close acReport, RptName, acSaveNo
       'Borrar el informe
       DoCmd.DeleteObject acReport, RptName
       
       Set rpt = Nothing
       If Err <> 0 Then Err.Clear
       Exit Sub
       
    Error_PrintPic:
        Dim ErrMsg As String
        'Mensaje de errores seleccionables
        Select Case Err.Number
            Case 2202
                ErrMsg = "There is no Printer attached to system." & vbCr & _
                         "Please attach Printer and try again."
            Case 2212
                ErrMsg = "Impresión cancelada por el usuario."
        
            Case Else
                ErrMsg = Err.Number & ": " & Err.Description
        End Select
        
        MsgBox ErrMsg, vbExclamation, "Gestor de fotos"
        Resume Exit_PrintPic

    End Sub

    • Edited by Ixxo09 Monday, November 13, 2017 2:39 PM
    • Marked as answer by Ixxo09 Monday, November 13, 2017 2:39 PM
    • Unmarked as answer by Ixxo09 Monday, November 13, 2017 2:40 PM
    • Marked as answer by Ixxo09 Monday, November 13, 2017 2:40 PM
    Monday, November 13, 2017 2:37 PM

All replies

  • It looks like the common dialog for WIA is loaded by a COM surrogate (dllhost) so that would mean it's running in a process that is separate from Microsoft Access. I would not advise attempting to turn this dll surrogate process into a modal window.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, November 9, 2017 7:55 PM
  • Hi Paul;

    Thanks for you promptly replay.

    I will consider your advice.  Thanks

    Coud You suggest me some ideas of how to do it?

    Thanks.

    Friday, November 10, 2017 8:00 AM
  • Hi lxxo09,

    Why do you want to make the dialog modal? What result do you want to achieve?

    Best Regards,

    Terry


    MSDN Community Support Please remember to click &amp;quot;Mark as Answer&amp;quot; the responses that resolved your issue, and to click &amp;quot;Unmark as Answer&amp;quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 13, 2017 8:15 AM
  • Hi Terry: 

    Thanks for reply.

    Check it yourself...

    https://www.dropbox.com/s/qzrg5hmbi81trm0/example%20whats%20happens.gif?dl=0

    Monday, November 13, 2017 10:02 AM
  • Hi Paul;

    Thanks for you promptly replay.

    I will consider your advice.  Thanks

    Coud You suggest me some ideas of how to do it?

    Thanks.


    Like I said you are dealing with two separate processes so attempting to display one application window (modally) over the other will be complicated and may not work reliably. You would have to set an Access (Form) window as the parent window to the WIA process window and that will require the use of some Windows API function calls. I can't guarantee this would always work as desired under current versions of Windows.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, November 13, 2017 1:36 PM
  • I have done it by the following way:

    Private Sub cmdImprimir_Click()

       'Declarar las variables locales
       Dim MyPicFile As String
       Dim rpt As New Report
       Dim RptName As String
       
       'Establecer la varible "MyPicFile" con el nombre de
       'la imagen a imprimir.  Aquí simplemente estamos usando
       'la función "DLookUp" para obtener la ruta completa de la Imagen,
       'en caso de estar almacenada en una tabla, sino puedes establecer
       ' esta variable como quieras.
       
       'MyPicFile = Nz(DLookup("[PicPath]", "[MyTable]", "[PicID]=" & Whatever), "")
       MyPicFile = Me!sfImagen!imgFoto.Picture
       
       'Sale de la función si la variable "MyPicFile"
       'no contiene nada (cadena vacía)
       If MyPicFile = vbNullString Then Exit Sub
       
       'Atrapa los errores...
       On Error GoTo Error_PrintPic

       'Crea un informe temporal
       Set rpt = CreateReport()
       
       'Establecer las propiedades del informe
       With rpt
          '.Visible = False
          .PictureType = 1      'Enlazada
          .PictureSizeMode = 3  'Zoom
          .Picture = MyPicFile  'Imagen a imprimir
          RptName = .Name
       End With
       
       'Imprime el informe
       DoCmd.OpenReport RptName, , , , acHidden

    Exit_PrintPic:
       On Error Resume Next
       'Cerrar el informe
       DoCmd.Close acReport, RptName, acSaveNo
       'Borrar el informe
       DoCmd.DeleteObject acReport, RptName
       
       Set rpt = Nothing
       If Err <> 0 Then Err.Clear
       Exit Sub
       
    Error_PrintPic:
        Dim ErrMsg As String
        'Mensaje de errores seleccionables
        Select Case Err.Number
            Case 2202
                ErrMsg = "There is no Printer attached to system." & vbCr & _
                         "Please attach Printer and try again."
            Case 2212
                ErrMsg = "Impresión cancelada por el usuario."
        
            Case Else
                ErrMsg = Err.Number & ": " & Err.Description
        End Select
        
        MsgBox ErrMsg, vbExclamation, "Gestor de fotos"
        Resume Exit_PrintPic

    End Sub

    • Edited by Ixxo09 Monday, November 13, 2017 2:39 PM
    • Marked as answer by Ixxo09 Monday, November 13, 2017 2:39 PM
    • Unmarked as answer by Ixxo09 Monday, November 13, 2017 2:40 PM
    • Marked as answer by Ixxo09 Monday, November 13, 2017 2:40 PM
    Monday, November 13, 2017 2:37 PM