Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2010
    Posts
    8

    Code needed when Database is Opened

    What would the code be to have a .mp3 (embedded or a set path) to start playing when the database is opened? Just looking to add a little pizazz to the database.

    P.S. There is only one form which is set to automatically open.



  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,921
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  3. #3
    Join Date
    Jun 2010
    Posts
    8

    I'm very new to this, what do I have wrong?

    I'm very new to this, what do I have wrong?


    Private Sub Form_Load()
    Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
    (ByVal filename As String, ByVal snd_async As Long) As Long

    Function PlaySound(sWavFile As String)
    ' Purpose: Plays a sound.
    ' Argument: C:\users\ocelco70\Desktop\escape.wav

    If apisndPlaySound(sWavFile, 1) = 0 Then
    MsgBox "The Sound Did Not Play!"
    End If
    End Function

    End Function

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,921
    Put the PlaySound() function in a Standard Module as Public. Then call it from the OnLoad event of your form with the name of the file you want to play as it shows in the link.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  5. #5
    Join Date
    Jun 2010
    Posts
    8
    Again, sorry for the ignorance but I know little to nothing about VBA Coding...yet. How do I call the file name from the Sub Form_Load()?

    Private Sub Form_Load()
    escape.wav

    End Sub
    Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
    (ByVal filename As String, ByVal snd_async As Long) As Long

    Function PlaySound(sPublic As String)
    ' Purpose: Plays a sound.
    ' Argument: C:\users\ocelco70\Desktop\escape.wav

    If apisndPlaySound(sPublic, 1) = 0 Then
    MsgBox "The Sound Did Not Play!"
    End If
    End Function

    End Function

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,921
    Start by creating a *new* module named SOUNDS and in it put the following:
    Code:
    Option Compare Database
    Option Explicit
     
    Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
        (ByVal filename As String, ByVal snd_async As Long) As Long
     
      Function PlaySound(sWavFile As String)
        ' Purpose:  Plays a sound.
        ' Argument: the full path and file name.
        If apisndPlaySound(sWavFile, 1) = 0 Then
            MsgBox "The Sound Did Not Play!"
        End If
      End Function
    ...in the OnLoad event you will then have:
    Code:
    Private Sub Form_Load()
    
      PlaySound("C:\users\ocelco70\Desktop\escape.wav")
     
    End Sub
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  7. #7
    Join Date
    Jun 2010
    Posts
    8
    Awesome! Works perfectly, thanks a million man.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,921
    Outstanding! Go ahead and follow the link in my sig and mark this thread as Solved.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

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

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2010, 10:35 PM
  2. Check if form is opened by other users
    By ser01 in forum Programming
    Replies: 2
    Last Post: 05-03-2010, 12:07 AM
  3. Replies: 0
    Last Post: 10-13-2009, 11:54 AM
  4. Mail Merge document locked when opened from Access
    By retro in forum Import/Export Data
    Replies: 0
    Last Post: 08-14-2009, 03:12 AM
  5. New database - help needed please :)
    By tonypony in forum Database Design
    Replies: 1
    Last Post: 07-29-2009, 04:40 AM

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 - Senior Forums