Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Unanswered: Run Program OnClick

    Hi,

    I am using MS Access 2003 SP2.

    I am developing a database of my mp3 music and have created so far the tables, queries, forms etc. to hold the song lists. One of my form queries using parameters searches and lists all songs with the entered keyword. From that I have set up where the person clicks on one of the titles in the list it runs the code below. The aim being to run Winamp playing that particular song.

    When it comes to coding I am not that familiar with some of the concepts and would ask please for some help in providing some example code to do this function. I have done some reading ( Access VBA Programming for Dummies) about sums me up ! ). I understand I think I need to focus on the actual field with something like Form! Or is it Me! Expression?

    The code below I have hard coded with a song title to see if I could make some progress. The code below runs Wimamp and the title in Winamp is the last word in the title, e.g. in this example “name” from “song file name”


    Private Sub Song_Click()

    Shell "C:\Program Files\Winamp\winamp.exe C:\Music\Collection\song file name.mp3"

    End Sub

    So could someone please give me some ideas about running Wimamp to play the song selected and how one can focus on the song title that has been selected ( clicked on ).

    Cheers,

    Vic.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You might want to take a look at this site:
    http://www.mvps.org/access/api/api0018.htm

    I used it and it worked great. It might give you some insight on shelling to the app to run your mp3 songs.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Oct 2004
    Posts
    3

    Reviewed code

    Hi Paul,

    I have had a look at the link you posted thank you. I found the code to complicated to follow to be honest, I am not that experienced with coding.

    Cheers,

    Vic.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Vic, You would copy the code snippet from the website, place it in a new module, and then to call the code the command would be:

    Call fHandleFile(MyFullPathAndFileNameHere, WIN_NORMAL)

    (The above would be the command to open your mp3 where MyFullPathAndFileNameHere is obviously substituted with the path and filename of your mp3 (you may need " around it depending on how you do it)).

    You really don't need to understand the code (I don't that much), but once you copy and paste it into a module, debug/compile, you're pretty much set to use it.

    Below is the code from the website. Take the code below and copy and paste it into a module:

    '************ Code Start **********
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

    '***App Window Constants***
    Public Const WIN_NORMAL = 1 'Open Normal
    Public Const WIN_MAX = 3 'Open Maximized
    Public Const WIN_MIN = 2 'Open Minimized

    '***Error Codes***
    Private Const ERROR_SUCCESS = 32&
    Private Const ERROR_NO_ASSOC = 31&
    Private Const ERROR_OUT_OF_MEM = 0&
    Private Const ERROR_FILE_NOT_FOUND = 2&
    Private Const ERROR_PATH_NOT_FOUND = 3&
    Private Const ERROR_BAD_FORMAT = 11&

    '***************Usage Examples***********************
    'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
    'Call Email app: ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMA L)
    'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
    'Handle Unknown extensions (call Open With Dialog):
    ' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
    'Start Access instance:
    ' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
    '************************************************* ***

    Function fHandleFile(stFile As String, lShowHow As Long)
    Dim lRet As Long, varTaskID As Variant
    Dim stRet As String
    'First try ShellExecute
    lRet = apiShellExecute(hWndAccessApp, vbNullString, _
    stFile, vbNullString, vbNullString, lShowHow)

    If lRet > ERROR_SUCCESS Then
    stRet = vbNullString
    lRet = -1
    Else
    Select Case lRet
    Case ERROR_NO_ASSOC:
    'Try the OpenWith dialog
    varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
    & stFile, WIN_NORMAL)
    lRet = (varTaskID <> 0)
    Case ERROR_OUT_OF_MEM:
    stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
    Case ERROR_FILE_NOT_FOUND:
    stRet = "Error: File not found. Couldn't Execute!"
    Case ERROR_PATH_NOT_FOUND:
    stRet = "Error: Path not found. Couldn't Execute!"
    Case ERROR_BAD_FORMAT:
    stRet = "Error: Bad File Format. Couldn't Execute!"
    Case Else:
    End Select
    End If
    fHandleFile = lRet & _
    IIf(stRet = "", vbNullString, ", " & stRet)
    End Function
    '************ Code End **********
    Last edited by pkstormy; 11-13-06 at 10:55.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •