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!!
Microsoft Access

Avatar of undefined
Last Comment
rockiroads

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
rockiroads

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
SiMsTeR

how do you stick it onto the form? just cut and paste? insert object? sorry i am a newbie..
rockiroads

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.

rockiroads

man, that was quick!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
SiMsTeR

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?
rockiroads

yea, property name might be misleading but basically

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

whhere do i key in the URL?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
rockiroads


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
ASKER
SiMsTeR

  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
ASKER
SiMsTeR

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..
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
rockiroads

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

ASKER
SiMsTeR

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?
rockiroads

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

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
SiMsTeR

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?
ASKER
SiMsTeR

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?
ASKER
SiMsTeR

is there anything i miss out? cos it still say run time error u see...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
rockiroads

tell u what, post your code (complete switchboard code), I shall have a look
ASKER
SiMsTeR

complete switchboard code? u mean the whole switchboard or just for the on load?
rockiroads

if the problem is current on the load, then just post that for the time being
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
SiMsTeR

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...
rockiroads

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


ASKER
SiMsTeR

compile error : variable not define
highlighted the wmplayer on the code
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
rockiroads

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)

ASKER
SiMsTeR

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?
rockiroads

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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
SiMsTeR

instead of linking the file to the database, can we include the file to the data base itself?
rockiroads

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
ASKER
SiMsTeR

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
Your help has saved me hundreds of hours of internet surfing.
fblack61
rockiroads

eh no worries

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

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?
rockiroads

try what I told you earlier about creating a table with one field being an ole object
then insert your media info in there
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
SiMsTeR

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


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 '")

ASKER
SiMsTeR

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
rockiroads

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")
ASKER
SiMsTeR

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.
rockiroads

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



Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
SiMsTeR

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

????
ASKER
SiMsTeR

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

we tried this... but still fail...
rockiroads

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
SiMsTeR

so the file insert where then? under which field?
rockiroads

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")
ASKER
SiMsTeR

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.
 
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
rockiroads

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



ASKER
SiMsTeR

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

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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
rockiroads

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
rockiroads

ASKER
SiMsTeR

can ask ur fellow colleage about this?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
rockiroads

Unfortunately Im the only technie on this project
all other people are accountants and managers

sorry
ASKER
SiMsTeR

okie... do you think there is any other place or forum that might be useful?
rockiroads

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes