hi
I want to make a custom message box alert just like VB6 built-in "VBOKCancel"....In that custom message box alert, i want the functionality of "VBOKCancel" as well as an additional button and check boxes.....much appreciated if anybody helps me out.

Thanx

Dani AI

Generated

The simplest way to get VB6-style behavior plus extras is to wrap a small dialog form that returns a VbMsgBoxResult and exposes any checkbox state. That keeps / right for in-app use, while ’s ActiveX idea is great when you must call it from VBScript or other hosts.

' In form dlgCustom: Label lblText, CommandButtons cmdOK/cmdCancel/cmdExtra,
' CheckBox chkDontAsk. Set BorderStyle=3, ShowInTaskbar=False, StartUpPosition=1.
Option Explicit
Private mResult As VbMsgBoxResult
Public Property Get Checked() As Boolean: Checked = (chkDontAsk.Value = vbChecked): End Property

Public Function ShowDialog(ByVal Text As String, ByVal Title As String, _
    Optional ByVal okCaption As String = "OK", _
    Optional ByVal cancelCaption As String = "Cancel", _
    Optional ByVal extraCaption As String = "", _
    Optional ByVal showCheck As Boolean = False) As VbMsgBoxResult

    Me.Caption = Title
    lblText.Caption = Text
    cmdOK.Caption = okCaption:   cmdOK.Default = True
    cmdCancel.Caption = cancelCaption: cmdCancel.Cancel = True
    cmdExtra.Visible = (Len(extraCaption) > 0)
    If cmdExtra.Visible Then cmdExtra.Caption = extraCaption
    chkDontAsk.Visible = showCheck
    Me.Show vbModal
    ShowDialog = mResult
End Function

Private Sub cmdOK_Click():     mResult = vbOK:     Unload Me: End Sub
Private Sub cmdCancel_Click(): mResult = vbCancel: Unload Me: End Sub
Private Sub cmdExtra_Click():  mResult = vbRetry:  Unload Me: End Sub  'or define your own Enum

Usage:

Dim r As VbMsgBoxResult, dlg As New dlgCustom
r = dlg.ShowDialog("Continue processing?", "My App", "OK", "Cancel", "More...", True)
If r = vbOK And dlg.Checked Then 'handle "dont ask again"
    ' ...
End If

: if you style the box as vbOKCancel, test vbOK/vbCancel, not vbYes/vbNo. Also avoid double MoveNext:

Do While Not rs.EOF
    If MsgBox(InfoString, vbOKCancel, "Title") = vbCancel Then Exit Do
    rs.MoveNext
Loop

: stock MsgBox sound is the system sound; you cannot change it per call. In a custom form, play your own WAV:

' In a BAS module
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
 (ByVal s As String, ByVal h As Long, ByVal f As Long) As Long
Public Const SND_ASYNC = &H1, SND_FILENAME = &H20000

' e.g., in dlgCustom.Form_Load
Call PlaySound("C:\sounds\notify.wav", 0, SND_ASYNC Or SND_FILENAME)

Recommended Answers

All 8 Replies

Err... Why don't you just make a new form (frmMsgBox)?

You can just do something like:

frmMsgBox!Text1 = "Testing, 1,2,3"
Load frmMsgBox
frmMsgBox.Show

You can change frmMsgBox!Text1 = "" to whatever you want the message to say. You can add buttons, an icon, etc to it.

Does that work?

I did exactly what you are talking about doing and made it an ActiveX dll using VB6. This is a message box with four large buttons. When you call the message box, you pass in the title for the message box window and you also pass in at least one string value for the button captions, and up to four string values to cover all the button captions. This function will then pass the value back that was pressed.

I'm using one class module and one form module. Here's the code I'm using:

cMsgBoxes Class Module Code:

Option Explicit

Public Function MsgBox4Button(strTitle As String, strcmd1 As String, Optional strcmd2 As String = " ", Optional strcmd3 As String = " ", Optional strcmd4 As String = " ") As String
   
    With frmMsgBox4Button
        .Caption = strTitle
        .cmd1.Caption = strcmd1
        .cmd2.Caption = strcmd2
        .cmd3.Caption = strcmd3
        .cmd4.Caption = strcmd4
        If Trim(.cmd2.Caption) = "" Then .cmd2.Visible = False
        If Trim(.cmd3.Caption) = "" Then .cmd3.Visible = False
        If Trim(.cmd4.Caption) = "" Then .cmd4.Visible = False
    End With
    
    frmMsgBox4Button.Show 1
    MsgBox4Button = frmMsgBox4Button.Response
    Unload frmMsgBox4Button
   
End Function

frmMsgBox4Button Form Module Code:

Option Explicit

Public Response As String

Private Sub cmd1_Click()
    Response = cmd1.Caption
    Me.Hide
End Sub

Private Sub cmd2_Click()
    Response = cmd2.Caption
    Me.Hide
End Sub

Private Sub cmd3_Click()
    Response = cmd3.Caption
    Me.Hide
End Sub

Private Sub cmd4_Click()
    Response = cmd4.Caption
    Me.Hide
End Sub

Here's how I'm using this dll. I just keep it in the directory of my .exe or my VBScript file. No need to register this dll if you do that. I've compiled the project with the project name "MsgBoxes" and named the dll "MsgBoxes.dll". In my code I use late binding:

VBScript:

Dim objMsgBox, MyMsgBox

Set objMsgBox = CreateObject("MsgBoxes.cMsgBoxes")
MyMsgBox = objMsgBox.MsgBox4Button("What would you like to do?", "Go to work.", "Go Home.", "Go hang.")
MsgBox MyMsgBox

Set objMsgBox = Nothing

Why use Active-X? Just define a form, it's straight forward and simple.

My ActiveX dll can be used by VBScript. That was my whole point in making it an ActiveX dll. Really, it can be called from most any language.

Since he hasn't been back since he posted this request, I guess it doesn't really matter how cool or how easy a method is. He's just wasted our time...

i make a program with vb, this program about making a store .
i have a simple problem with this program
want to make a message box that can ok and cancelthat connect with a database to show some records from a tabel as sequential.
but i cannot make this button do its functions to be ok or cancel
can any one help me
this is the code of button that show the records:
Private Sub Command1_Click()
Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
Dim urmsg As Integer
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "min requirements.mdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open

With cmdCommand
.ActiveConnection = conConnection
.CommandText = "SELECT * FROM dealers;"
.CommandType = adCmdText

End With

With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmdCommand
End With

If rstRecordSet.EOF = False Then
rstRecordSet.MoveFirst
Do

urmsg = MsgBox("ÈíÇäÇÊ ÇáÓÌá" & rstRecordSet.AbsolutePosition & " " & _
rstRecordSet.Fields(0).Name & "=" & rstRecordSet.Fields(0) & " " & _
rstRecordSet.Fields(1).Name & "=" & rstRecordSet.Fields(1) & " " & _
rstRecordSet.Fields(2).Name & "=" & rstRecordSet.Fields(2) & " " & _
rstRecordSet.Fields(3).Name & "=" & rstRecordSet.Fields(3), vbOKCancel, "ÚÑÖ ÇáÚãáÇÁ")
rstRecordSet.MoveNext
Loop Until rstRecordSet.EOF = True
Select Case urmsg
Case 6 'If the user clicks "Yes" then...
rstRecordSet.MoveNext 'Quit the program
Case 7 'If the user click on No....
Exit Sub 'Then Exit the sub, not the program.
End Select
'With rstRecordSet
' .AddNew
' .Fields(0) = "New"
' .Fields(1) = "Record"
' .Update
'End With
'rstRecordSet.MoveFirst
'rstRecordSet.Delete
'rstRecordSet.Update
'rstRecordSet.Close
Else
MsgBox "Nn records were returned ushng the query " & cmdCommand.CommandText
End If
conConnection.Close
Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
End Sub

i just want to customize regular messagebox sound, is that possible?

serkan sendur,

Please start your own thread

No. You will have to make your own form that looks like a message box.

Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.