Dear Sir/Madam

I have a program where I have used a small form as Input / Message Box in place of VB’s InputBox / MsgBox in a click event procedure i.e CmdSave_Click(). Though the code lines are executing in that procedure at a time, the global variable GblBox is not getting the value 1 for executing SaveRecord procedure, which is passing by the FrmMsgBox(a form)’s CmdOK button.

So, can I hold/pause the code lines of Form1 from line no. 6 to 9 till passing the global variable’s value as like as InputBox. Or is there another way to solve. Please, help me to solve this problem. I am eagerly waiting for your reply.

Here are the Code lines

Codes of Form1

1. Private sub CmdSave_click()
2. Form1.enabled = False
3. Load FrmMsgBox
4. FrmMsgBox.visible = True
5. FrmMsgBox.label1.caption=”Do you want to save the record?”
6. If GblMsg=1 then
7. Call SaveRecord
8. End if
9. End Sub

10. Private Sub Form_Load()
11. GblMsg=0 ‘It is a Global variable
12. End Sub

Codes of FrmMsgBox

1. Private sub CmdOK_click()
2. GblMsg=1
3. End Sub

4. Private sub CmdCancel_click()
5. GblMsg=0
6. End Sub

Hi P.manidas,
I do believe that is possible but it require little effort. But I wonder why you choose not to use VB's MessageBox which is lot simple. The below code of VB's Message Box sereves the same purposes.

Private Sub Save_Click()
If MsgBox("Do you want to save the record?", vbYesNo) = vbYes Then
Call SaveRecord
Else
Exit Sub
End If
End Sub

If you really want in the manner you are asking now I will post my help later because now we have no power supply.

Thankx.

As kinwang2009 pointed out, the use of the msgbox function is called for here, but as you may be wanting to have a custom message box, you will need to show the form vbmodal and/or return a value from that form.

Load FrmMsgBox
FrmMsgBox.label1.caption=”Do you want to save the record?”
FrmMsgBox.Show vbModal, Me
If GblMsg = 1 Then Call SaveRecord

Then in FrmMsgBox you need to add Unload Me to each buttons click event AFTER you set your global variable...

Good Luck

Hi P.manidas,
I do believe that is possible but it require little effort. But I wonder why you choose not to use VB's MessageBox which is lot simple. The below code of VB's Message Box sereves the same purposes.

Private Sub Save_Click()
If MsgBox("Do you want to save the record?", vbYesNo) = vbYes Then
Call SaveRecord
Else
Exit Sub
End If
End Sub

If you really want in the manner you are asking now I will post my help later because now we have no power supply.

Thankx.

Dear Kinwang2009,

Thanks for your reply

Actually, i want a designable messagebox to be displayed, though i can design in a form so, i used the form as Messagebox in place of VB's MsgBox. Thanks once again and waiting for your reply as you have written.

As kinwang2009 pointed out, the use of the msgbox function is called for here, but as you may be wanting to have a custom message box, you will need to show the form vbmodal and/or return a value from that form.

Load FrmMsgBox
FrmMsgBox.label1.caption=”Do you want to save the record?”
FrmMsgBox.Show vbModal, Me
If GblMsg = 1 Then Call SaveRecord

Then in FrmMsgBox you need to add Unload Me to each buttons click event AFTER you set your global variable...

Good Luck

Dear Vb5prgrmr,

Thank you very much for your suitable reply, which really solve my problem.

Thank you once again.

OK P.manidas,
Find the attached Source Code. This source code was especially made for you to go ahead with your project.

Hope this helps
Rate my post if helpful.

Dear Kinwang2009/VBprgrmr,

Thanks for your soft copy Kinwang2009, which you had prepared for me.

Here i have attached both the programe which i prepare taking the solution code from both VBprgmr and Kinwang2009. Both the solution are good which meet the requirement of my programe. But i think vbprgrmr's solution is best.

Thank you All

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.