Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a custom dialog form and know the clicked closing button 1

Status
Not open for further replies.

polocar

Programmer
Sep 20, 2004
89
IT
Hi,
I'm writing a program using VBA 2003, I have a Form called "Form1" that has 1 "txtName" TextBox and 1 "btnOpen" CommandButton.
I would like that, when the user clicks on "btnOpen", another modal form (called "Form2") opens, where the user can insert a text in a "txtNameInsert" TextBox and then click on a "btnOk" CommandButton or "btnCancel" CommandButton.
If the user clicks on "btnOk", the text of "Form2.txtNameInsert" should be copied into "Form1.txtName" (and then "Form2" closes automatically), and if he clicks on "btnCancel", no text should be copied from one TextBox to another (and then "Form2" closes automatically).

In Form1 I prepared the event handler:

Private Sub btnOpen_Click()

DoCmd.OpenForm "Form2" 'Form2 already set in modal mode

End Sub

In Form2 I prepared the variables:

Public blnOk As Boolean
Public blnCancel As Boolean

and the event handlers:

Private Sub btnOk_Click()

blnOk = True

End Sub

Private Sub btnCancel_Click()

blnCancel = True

End Sub

Using this code, how can I obtain what I want? (in other words, I would like to obtain a custom dialog form where in the main window I can understand if the user has clicked on btnOk or btnCancel, and what he has written in the inner of the form...)
Thanks for the help
 
No need of global variables at all:
Code:
Private Sub btnOk_Click()
Forms![Form1]![txtName] = Me![txtNameInsert]
DoCmd.Close
End Sub

Private Sub btnCancel_Click()
DoCmd.Close
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top