Solved

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

Posted on 2004-03-29
52
1,054 Views
Last Modified: 2008-03-10
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!!
0
Comment
Question by:SiMsTeR
  • 27
  • 25
52 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 125 total points
ID: 10703707
you could use a window media player control, stick it onto the form

the the code to load up a file is

wmPlayer.URL = <full path of file>

now unsure when that is playing you can use other parts of the database, I think you can but might want to check this

as switchboard is left open all the time, in theory, the music should continue playing
0
 

Author Comment

by:SiMsTeR
ID: 10703756
how do you stick it onto the form? just cut and paste? insert object? sorry i am a newbie..
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10703827
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.

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10703854
man, that was quick!
0
 

Author Comment

by:SiMsTeR
ID: 10703881
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10703899
yea, property name might be misleading but basically

WMPcontrolName.URL = "C:\MyMusic\IntroMusic.mp3"
0
 

Author Comment

by:SiMsTeR
ID: 10703913
whhere do i key in the URL?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10703945

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
0
 

Author Comment

by:SiMsTeR
ID: 10704049
  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
0
 

Author Comment

by:SiMsTeR
ID: 10704093
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..
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10704099
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

0
 

Author Comment

by:SiMsTeR
ID: 10704217
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10704284
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

0
 

Author Comment

by:SiMsTeR
ID: 10704373
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?
0
 

Author Comment

by:SiMsTeR
ID: 10704457
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?
0
 

Author Comment

by:SiMsTeR
ID: 10704662
is there anything i miss out? cos it still say run time error u see...
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10704694
tell u what, post your code (complete switchboard code), I shall have a look
0
 

Author Comment

by:SiMsTeR
ID: 10704712
complete switchboard code? u mean the whole switchboard or just for the on load?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10704734
if the problem is current on the load, then just post that for the time being
0
 

Author Comment

by:SiMsTeR
ID: 10704806
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...
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10704901
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


0
 

Author Comment

by:SiMsTeR
ID: 10704954
compile error : variable not define
highlighted the wmplayer on the code
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10705028
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)

0
 

Author Comment

by:SiMsTeR
ID: 10705063
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10705245
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?
0
 

Author Comment

by:SiMsTeR
ID: 10705334
instead of linking the file to the database, can we include the file to the data base itself?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 65

Expert Comment

by:rockiroads
ID: 10705362
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
0
 

Author Comment

by:SiMsTeR
ID: 10705431
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10711917
eh no worries

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

Author Comment

by:SiMsTeR
ID: 10712910
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10713023
try what I told you earlier about creating a table with one field being an ole object
then insert your media info in there
0
 

Author Comment

by:SiMsTeR
ID: 10713028
we can insert but we dun know how to link it and play
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10713181

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

0
 

Author Comment

by:SiMsTeR
ID: 10713629
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10713809
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")
0
 

Author Comment

by:SiMsTeR
ID: 10713851
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.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10713948
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



0
 

Author Comment

by:SiMsTeR
ID: 10714042
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

????
0
 

Author Comment

by:SiMsTeR
ID: 10714051
   sFile= NZ(DLookup(("URL", "Table1", "RowID = 1"), "")
End Sub

we tried this... but still fail...
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10714120
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
0
 

Author Comment

by:SiMsTeR
ID: 10714183
so the file insert where then? under which field?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10714223
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")
0
 

Author Comment

by:SiMsTeR
ID: 10714331
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.
 
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10714607
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



0
 

Author Comment

by:SiMsTeR
ID: 10714636
we did not set any sfile, how do we set one? can guide us step by step? sorry...
0
 

Author Comment

by:SiMsTeR
ID: 10716238
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10722842
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10722866
0
 

Author Comment

by:SiMsTeR
ID: 10724638
can ask ur fellow colleage about this?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10724828
Unfortunately Im the only technie on this project
all other people are accountants and managers

sorry
0
 

Author Comment

by:SiMsTeR
ID: 10725485
okie... do you think there is any other place or forum that might be useful?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10729958
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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now