Link to home
Start Free TrialLog in
Avatar of SiMsTeR
SiMsTeR

asked on

How do i play music file MS Access when i am using switchboard?

i am trying to figure out how to play music file when i am in  switchboard view.. i have to present my project on access.. so i thought playing music while presenting is a cool thing to do, please help me!!
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SiMsTeR
SiMsTeR

ASKER

how do you stick it onto the form? just cut and paste? insert object? sorry i am a newbie..
do you know how to create controls onto a form at the moment (basically click on what you want on the toolbox then click on form to create it)

the last button on the toolbox (got a hammer on it and is called 'More Controls')
well click on that, go towards the bottom to find Windows Media Player control

then add that onto your form - you will see a WMP design

if you want to automatically play a file, then on form_load just set the URL property.

man, that was quick!
Avatar of SiMsTeR

ASKER

wat do u mean by on form_load? i can get the media player on my form already.. nowi  dun know where to key in the URL.
URL as in the path to the file?
yea, property name might be misleading but basically

WMPcontrolName.URL = "C:\MyMusic\IntroMusic.mp3"
Avatar of SiMsTeR

ASKER

whhere do i key in the URL?

on your switchboard, in design mode, if you click on the form part (any part of the form outside the detail) then go to properties, the click (right hand side) on "On Load", select code builder

it should create a code for you called

private sub Form_Load()

end sub

put your code in there, so each time form is loaded, it will assign the full pathname of your media file, load and play it
Avatar of SiMsTeR

ASKER

  Option Compare Database

Private Sub Form_Load()

End Sub

Private Sub Form_Load(wmPlayer.URL = C:\Documents and Settings\Sin\Desktop\BMP\Hey Mama.mp3)

End Sub

i type in the above but still fail, it say compile error, expect : list separator or)
still fair.. then it highlight the . at the wmPlayer.URL
Avatar of SiMsTeR

ASKER

now i have a problem, i could not see all the shortcut on my original switchboard.. it say got error with the form_load... although my link in my switchboard manager is all there, but there are not showing in my main switchboard..
na, tis like this

private sub Form_Load

    wmPlayer.URL = "C:\Documents and Settings\Sin\Desktop\BMP\Hey Mama.mp3"

end sub


is the name of the control you created called wmPlayer? whatever name is given to that control is the name you use here

Avatar of SiMsTeR

ASKER

okie.. its window media player.. but now everything on the switchboard got problem, i cant display my normal stuff on it, all the shortcut to the reports are gone.. although the link is still in the manager. just now when we try to do it, we accidentally deleted the event procedure for on current and on open, now we try to change it back to event procedure it just doesnt work anymore.. please help...

furthermore, the

private sub Form_Load

    wmPlayer.URL = "C:\Documents and Settings\Sin\Desktop\BMP\Hey Mama.mp3"

end sub

there is 2 of the private sub form for us, which one we key in, the top one or e bottom one? or is it suppose to be only one of those?
there must of been some switchboard code in the first place, you have not touched that right?

if you already have a Form_Load code, (or Form_Open) then just put that wmPlayer.URL line in there

you cannot have two of the same procedures, just one Form_Load and one Form_Open

have you got a working switchboard at all (i.e. you havent saved this form)

if not, try doing menu option "Edit, Undo ..." to see if you can get back your code

Avatar of SiMsTeR

ASKER

it say runtime error 424, object required... wat does it mean.. i already deleted my switch board.. redo it again.. now just testing it on a new switchboard... so i go to the property then at on load, choose event procedure right?
Avatar of SiMsTeR

ASKER

step by step, first i stick a window media player onto the form.
2. right click outside of the form select property, choose on load, choose event procedure then to the right of it there is a ... icon for u to click, click on it, come to this page full of command, at the top, the sub form thing, we type in

private sub Form_Load

    wmPlayer.URL = "C:\Documents and Settings\Sin\Desktop\BMP\Hey Mama.mp3"

end sub


so save it and run the switchboard n it should work rite?
Avatar of SiMsTeR

ASKER

is there anything i miss out? cos it still say run time error u see...
tell u what, post your code (complete switchboard code), I shall have a look
Avatar of SiMsTeR

ASKER

complete switchboard code? u mean the whole switchboard or just for the on load?
if the problem is current on the load, then just post that for the time being
Avatar of SiMsTeR

ASKER

Option Compare Database
Private Sub Form_Load()
    wmPlayer.URL = "C:\Documents and Settings\Sin\Desktop\HeyMama.mp3"
End Sub
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.
    ' Move to the switchboard page that is marked as the default.
    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    Me.FilterOn = True
   
End Sub
Private Sub Form_Current()
' Update the caption and fill in the list of options.
    Me.Caption = Nz(Me![ItemText], "")
    FillOptions
   
End Sub
Private Sub FillOptions()
' Fill in the options for this switchboard page.
    ' The number of buttons on the form.
    Const conNumButtons = 8
   
    Dim con As Object
    Dim rs As Object
    Dim stSql As String
    Dim intOption As Integer
   
    ' Set the focus to the first button on the form,
    ' and then hide all of the buttons on the form
    ' but the first.  You can't hide the field with the focus.
    Me![Option1].SetFocus
    For intOption = 2 To conNumButtons
        Me("Option" & intOption).Visible = False
        Me("OptionLabel" & intOption).Visible = False
    Next intOption
   
    ' Open the table of Switchboard Items, and find
    ' the first item for this Switchboard Page.
    Set con = Application.CurrentProject.Connection
    stSql = "SELECT * FROM [Switchboard Items]"
    stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID]
    stSql = stSql & " ORDER BY [ItemNumber];"
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open stSql, con, 1   ' 1 = adOpenKeyset
   
    ' If there are no options for this Switchboard Page,
    ' display a message.  Otherwise, fill the page with the items.
    If (rs.EOF) Then
        Me![OptionLabel1].Caption = "There are no items for this switchboard page"
    Else
        While (Not (rs.EOF))
            Me("Option" & rs![ItemNumber]).Visible = True
            Me("OptionLabel" & rs![ItemNumber]).Visible = True
            Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
            rs.MoveNext
        Wend
    End If
    ' Close the recordset and the database.
    rs.Close
    Set rs = Nothing
    Set con = Nothing
End Sub
Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.
    ' Constants for the commands that can be executed.
    Const conCmdGotoSwitchboard = 1
    Const conCmdOpenFormAdd = 2
    Const conCmdOpenFormBrowse = 3
    Const conCmdOpenReport = 4
    Const conCmdCustomizeSwitchboard = 5
    Const conCmdExitApplication = 6
    Const conCmdRunMacro = 7
    Const conCmdRunCode = 8
    Const conCmdOpenPage = 9
    ' An error that is special cased.
    Const conErrDoCmdCancelled = 2501
   
    Dim con As Object
    Dim rs As Object
    Dim stSql As String
On Error GoTo HandleButtonClick_Err
    ' Find the item in the Switchboard Items table
    ' that corresponds to the button that was clicked.
    Set con = Application.CurrentProject.Connection
    Set rs = CreateObject("ADODB.Recordset")
    stSql = "SELECT * FROM [Switchboard Items] "
    stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
    rs.Open stSql, con, 1    ' 1 = adOpenKeyset
   
    ' If no item matches, report the error and exit the function.
    If (rs.EOF) Then
        MsgBox "There was an error reading the Switchboard Items table."
        rs.Close
        Set rs = Nothing
        Set con = Nothing
        Exit Function
    End If
   
    Select Case rs![Command]
       
        ' Go to another switchboard.
        Case conCmdGotoSwitchboard
            Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
           
        ' Open a form in Add mode.
        Case conCmdOpenFormAdd
            DoCmd.OpenForm rs![Argument], , , , acAdd
        ' Open a form.
        Case conCmdOpenFormBrowse
            DoCmd.OpenForm rs![Argument]
        ' Open a report.
        Case conCmdOpenReport
            DoCmd.OpenReport rs![Argument], acPreview
        ' Customize the Switchboard.
        Case conCmdCustomizeSwitchboard
            ' Handle the case where the Switchboard Manager
            ' is not installed (e.g. Minimal Install).
            On Error Resume Next
            Application.Run "ACWZMAIN.sbm_Entry"
            If (Err <> 0) Then MsgBox "Command not available."
            On Error GoTo 0
            ' Update the form.
            Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
            Me.Caption = Nz(Me![ItemText], "")
            FillOptions
        ' Exit the application.
        Case conCmdExitApplication
            CloseCurrentDatabase
        ' Run a macro.
        Case conCmdRunMacro
            DoCmd.RunMacro rs![Argument]
        ' Run code.
        Case conCmdRunCode
            Application.Run rs![Argument]
        ' Open a Data Access Page
        Case conCmdOpenPage
            DoCmd.OpenDataAccessPage rs![Argument]
        ' Any other command is unrecognized.
        Case Else
            MsgBox "Unknown option."
   
    End Select
    ' Close the recordset and the database.
    rs.Close
   
HandleButtonClick_Exit:
On Error Resume Next
    Set rs = Nothing
    Set con = Nothing
    Exit Function
HandleButtonClick_Err:
    ' If the action was cancelled by the user for
    ' some reason, don't display an error message.
    ' Instead, resume on the next line.
    If (Err = conErrDoCmdCancelled) Then
        Resume Next
    Else
        MsgBox "There was an error executing the command.", vbCritical
        Resume HandleButtonClick_Exit
    End If
   
End Function
Private Sub Go_Back_Click()
On Error GoTo Err_Go_Back_Click

    DoCmd.GoToRecord , , acPrevious
Exit_Go_Back_Click:
    Exit Sub
Err_Go_Back_Click:
    MsgBox Err.Description
    Resume Exit_Go_Back_Click
   
End Sub


Sorry to bother u.. i know its abit long... thanks for u...
well the code looks ok, typical switchboard code

try this go into modules (which u should be when viewing code)
then go into Tools/References

check that Microsoft Windows Media Player is clicked, if not then check it and click ok

going back to switchboard code code, add this to the top

option explicit

then do Debug/Compile

tell me what line it falls over and what exact error message appears


Avatar of SiMsTeR

ASKER

compile error : variable not define
highlighted the wmplayer on the code
ok, when you created the media player control on the form, what is its name (click on it and see the properties window)
what is its name

you then use that (or rename that to wmPlayer)

Avatar of SiMsTeR

ASKER

okie.. do u have icq? can give us ur no.? we add u, easier to talk like that. can?
now it work, how does it loop the song?
how to embed?
sorry, no icq

I do this from work

Im off in about 10mins, I have to catch a train to get home

so quick questions now until tomorrow

when you create the control on your form, you simply need to set properties within the code (like we have done)

so when you specify URL, it will load and play the song

with regards to looping, I am unsure what the property is, I shall try find out for you

and what do you mean by embed?
Avatar of SiMsTeR

ASKER

instead of linking the file to the database, can we include the file to the data base itself?
yes, thats possible, I think

something about having a table where one of the fields is of type OLE Object (instead of number or text)

then you can set your file info there

unsure though but have a try

check this link out

http://www.oreilly.com/catalog/accesscook/

goto the CD-ROM link and download the cookbook, see if any useful info is there for you
Ive downloaded it but have yet to see how good it is
Avatar of SiMsTeR

ASKER

thanks again... so just help me check the loop thing and also the embed thing alright? just post it here .. sorry to trouble you with all these thing.. but the moment i hear the music playing, i was so.. how to say.. so freaking excited and both me n my roomie think u r a genius man!!! Way to go man.. i mean access is so... not our cup of tea but hearing reply from u is a god send man.. thanks again
eh no worries

its quite lucky actually, I only just figured this out last week - havent figured out the looping yet though
Avatar of SiMsTeR

ASKER

i have already solve the problem of looping already, i just edit my clip and make it ultra long. same as looping anyway. now i just need to know how to embed it into the database, any luck with dat?
try what I told you earlier about creating a table with one field being an ole object
then insert your media info in there
Avatar of SiMsTeR

ASKER

we can insert but we dun know how to link it and play

there is a function called DLookup used to extract one value from one table

DLookup("field","table","where clause")

so if you created a table say its called tblMedia

has a rowid, name and url

so data is

1, "Switchboard","C:\MyMusic\Fred.mp3"

then you can use dlookup to get the URL

e.g.

sURL = DLookup(url,tblMedia,"RowID = 1")

or

sURL = DLookup(url, tblMedia, "Name = 'Switchboard '")

Avatar of SiMsTeR

ASKER

is it like this?
   wmplayer.sURL = DLookup(URL, table1, "RowID = 1")

we tried this but say run time error 2428, enter an invalid arguement in a domain arguement
what is your table called that you  created which holds the pathname of the media file?
what is the field name

once done, put them in double quotes

example

DLookup("url","table1","RowiD = 1")
Avatar of SiMsTeR

ASKER

table1 is the name....

we tried

   wmplayer.sURL = DLookup("URL", "table1", "RowID = 1") it say run time error 2001, you just cancel the previous operation.
why have you got wmPlayer.sURL - should be no s, just .URL



also does the table "table1" exist?

and does it contain a field called DLOokup

also do it this way

dim sFile as string


sFile= NZ(DLookup(("URL", "table1", "RowID = 1"), "")

if sFile = "" then
   msgbox "Failed to find media file"
else
   wmPlayer.URL = sFle



Avatar of SiMsTeR

ASKER

the table 1 exist, there is no field called DLOokup, so we create a field call DLOokup?
just create a field in the table1?

sorrie we are newbie... really haf no idea wat u mean by

if sFile = "" then
   msgbox "Failed to find media file"
else
   wmPlayer.URL = sFle

????
Avatar of SiMsTeR

ASKER

   sFile= NZ(DLookup(("URL", "Table1", "RowID = 1"), "")
End Sub

we tried this... but still fail...
do you have a table called table1 defined?

YES? if so then do you have fields defined called

URL and RowID

YES? then please post exact error msg

otherwise you need to create a table with those fields
Avatar of SiMsTeR

ASKER

so the file insert where then? under which field?
learn to create a table first - pleasse see this

http://www.online.tusc.k12.al.us/tutorials/access/acctab.htm


each field you have has a datatype i.e. string, number etc
forget about ole objects, just create a simple table

call it

tblMedia

have the following fields

RowID   (type number)
Name    (type string)
URL       (type string)

the values should be

RowID  (1)
Name   (Switchboard)
URL     (C:\... your path)

then do DLOOKUP("url","tblMedia","RowID = 1")
Avatar of SiMsTeR

ASKER

we created the table called tblMedia, wit field RowID, Name and URL.
like wat u say..  then we type exactly like below

   Private Sub Form_Load()
    sFile = DLookup("url", "tblMedia", "RowID = 1")
End Sub

but then when we on the switch board, no error message but nothing happen too.
 
ok you set sFile
now do this after setting sFile

msgbox "Media File is " & sFile
wmPlayer.URL = sFile


you should get a message box appearing with a message "Media File is " ...
then it should load it into wmPlayer

once your happy, remove the msgbox line



Avatar of SiMsTeR

ASKER

we did not set any sfile, how do we set one? can guide us step by step? sorry...
Avatar of SiMsTeR

ASKER

so okie... i did the thing liao.. music all on... sorry to be such a fool.. haha but thanks for ur help man! really apreciate it!! thanks a million!!
so let me confirm, so if i save my database onto a cd, the music is embedded into the database, so now it will alway follow the database, so we do not need to always change the url of the song rite?
urm, the simple example we went thru was to store the path on the database, not the object itself

if you need to embed the object, you need to create a field of type OLE OBJECT in your table
then go into datasheet view, insert your media thru there

Im not that hot on this area so I cant really help you on this, dont want to give you duff info,
suggest you maybe look it up, perhaps the microsoft website
Avatar of SiMsTeR

ASKER

can ask ur fellow colleage about this?
Unfortunately Im the only technie on this project
all other people are accountants and managers

sorry
Avatar of SiMsTeR

ASKER

okie... do you think there is any other place or forum that might be useful?
hmm, dunno, look in google or search EE

since your original question was not about embedding, you could try posting another question to see if anyone knows