Results 1 to 7 of 7
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    Code to call from a Module

    1.Some good man has taught me a lot to call code from a module, truly grateful for that. I obtained good skill there.
    2.Another says I am drawing blood from a stone. Here comes more difficult stuff.
    3.In the test DB that I attached here, open form f6ObjectTypes.
    4.In the top right corner there are 10 buttons.
    5.It is set up to call video, audio or Word documents through a Module. The button 6th from left is named "btn06TutrlVideo".
    6.This button opens video from my directory D:\Attachments\TutorialsVideo\ .


    7.See Module named "BtnWordDocuments". Last three lines. Also, the VBA linked to the button. It opens the videos as required.
    8. I have no idea how to do the following, or if it can be done.


    a.I would like a Msgbox message to come up if the named video clip is not found in the directory. Let's say the message is "No video found".
    b.If the clip is found, it must just play it, like it does now.
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    here is code for the form when on a record.
    here the text box, txtVideoSrc , holds the path of the file.


    Code:
    
    if fileExists(txtVideoSrc) then
        OpenNativeApp  txtVideoSrc
    else
       msgbox "File does not exist:" & txtVideoSrc
    endif



    paste this code into a module


    Code:
    Option Compare Database
    Option Explicit
    
    
    #If Win64 Then
      'Declare PtrSafe Sub...
        Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
        Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #Else
       Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
       Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    
    
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, Msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                Msg = "File not found"
            Case SE_ERR_PNF
                Msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                Msg = "Access denied"
            Case SE_ERR_OOM
                Msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                Msg = "DLL not found"
            Case SE_ERR_SHARE
                Msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                Msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                Msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                Msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                Msg = "DDE busy"
            Case SE_ERR_NOASSOC
                Msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                Msg = "Invalid EXE file or error in EXE image"
            Case Else
                Msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function
    
    
    
    
    
    
    
    
    Public Function FileExists(ByVal pvFile) As Boolean
    Dim fso 'As FileSystemObject
    On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")
    FileExists = fso.FileExists(pvFile)
    Set fso = Nothing
    End Function

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Sub OpenTutorial06(tutName06 As String)
    
    
        If Len(Dir("D:\Attachments\TutorialsVideo\" & tutName06 & ".mp4")) = 0 Then
            MsgBox "This file does NOT exist."
        Else
            FollowHyperlink "D:\Attachments\TutorialsVideo\" & tutName06 & ".mp4"
        End If
        
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the Dir() function, for example:

    Code:
      If Len(Dir(strFile)) = 0 Then
        MsgBox "Excel Template file not found - see Paul"
        GoTo ExportExit
      End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, slow fingers today.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Thank you Moke123. Simple. I am embarrassed.

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    The OpenNativeApp() can open ANY file... .Doc files open in Word, .xls in excel, etc.
    A good tool to have.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-10-2020, 05:32 PM
  2. Replies: 14
    Last Post: 11-06-2017, 12:26 PM
  3. Replies: 9
    Last Post: 09-29-2017, 02:04 PM
  4. How to call module using commandline
    By Ranjiz in forum Modules
    Replies: 1
    Last Post: 06-20-2012, 07:50 AM
  5. Call .dll Code On BeforeUpdate?
    By phi11yguy19 in forum Programming
    Replies: 0
    Last Post: 07-02-2011, 10:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums