2

I am working on VBA form, where user need to pass a ComboBox condition like below -

Private Sub ComboBox4_AfterUpdate()
    Dim ws As Worksheet
    Set ws = Worksheets("PRODUCT")

    Fnsearch = ComboBox4.Value
    Set searchRange = ws.Range("B:B")
    Set foundCell = searchRange.Find(What:=Fnsearch, After:=searchRange.Cells(searchRange.Cells.Count))

    If Not foundCell Is Nothing Then
        ' Doing some form work
        ' And want play notification sound here for user
    Else
        ' Want play notification sound here for user
        rslt = MsgBox("Kindly check product name which you typed." & vbCr & _
                      "Because this Item is not available in PRODUCT page." & vbCr & vbCr & _
                      "Kindly click Yes to Add Product or No to Discard.", vbYesNo, "Product not exists")
        If rslt = vbYes Then
            AddPartyA.Show
        End If
    End If
End Sub
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
IshaniNet
  • 153
  • 10
  • 1
    You can simply write Beep to add sound. – Imran Malek Sep 11 '18 at 11:09
  • Actually i want to play custom sound there – IshaniNet Sep 11 '18 at 11:12
  • 2
    Have you looked at the PlaySound API? [StackOverflow has an example for it in VB6](https://stackoverflow.com/questions/15981272/how-to-play-a-sound-in-vb6-with-playsound), which you can easily adapt for VBA. I will offer this advice, from bitter experience: never use the 'play on eternal loop' option; and never, ever, give the users any opportunity to customise their audible alerts - your office will sound like a barnyard if they do. – Nigel Heffernan Sep 11 '18 at 11:13
  • You can follow this [tutorial](http://www.cpearson.com/excel/PlaySound.aspx) – Imran Malek Sep 11 '18 at 11:15
  • I used `Private Const SND_FILENAME As Long = &H20000` and then `PlaySound "D:\Sounds\ok.wav", 0, SND_FILENAME` but that shown Compile error, Expected = – IshaniNet Sep 11 '18 at 11:19
  • Sub or Function not defined – IshaniNet Sep 11 '18 at 11:22
  • 2
    @SftAps Please [edit] your post to add the code your tried and the resultant error information, instead of posting in comments. – ashleedawg Sep 11 '18 at 11:29
  • I used this two line `Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Const SND_FILENAME As Long = &H20000` from [link](http://www.vbaexpress.com/forum/showthread.php?31771-Solved-Play-wav-sound-file-when-userform-opened), now working my code – IshaniNet Sep 11 '18 at 11:41
  • Thanks to all of you to suggest me and for giving your time – IshaniNet Sep 11 '18 at 11:42

0 Answers0