Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Call other FORM from Main-form,  asking for INPUT$ on 2e. form, How to get this in Mainform

Posted on 2004-08-20
8
Medium Priority
?
172 Views
Last Modified: 2013-12-25
In mainform we load a form with some cmdbuttons, below is the one
'*************************
Public Password as string

Public Sub cmdRsa_Click()
'  ask for password on Form RSA with name in textinputbox: txtOwner
  rSa.Show vbModal
  rSa.Hide
'  here I need the value entered in form RSA
printer.print txtOwner.Text gives nothing
End Sub


Form RSA has only one input textbox, name txtOwner

How do I get answer typed in form Rsa at location Mainform  ???
   
Thank you for help
Jack

0
Comment
Question by:BIAPRO
8 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 11855378
becuase its on a different form, it doesnt know what txtOwner.Text is

save the value to the registry, place this code in your rSa from under the event you use to close the form....This will save whatever value is in txtinputbox.Text to the registry

SaveSetting("your_program_name", "rSa", "pass", textinputbox.Text)

then, you need to call the value, you can place this code after your comment  " ' here i need the value entered in form RSA"

dim blah as string
blah = GetSetting("your_program_name", "rSa", "pass")

your password should be in the variable blah

~b
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 11855433
Here is an easier solution:

' ----------------------------------------------------------------------------
' Main Form
' ----------------------------------------------------------------------------
Option Explicit

Private WithEvents rsa As rsaForm

Private Sub cmdRsa_Click()
    Set rsa = New rsaForm
    rsa.Show vbModal
End Sub

Private Sub rsa_rsaMessage(ByVal answer As String)
    MsgBox answer
End Sub

' ----------------------------------------------------------------------------
' RSA Form called rsaForm with only one TextBox called txtOwner
' ----------------------------------------------------------------------------
Option Explicit

Public Event rsaMessage(ByVal answer As String)

Private Sub Form_Unload(Cancel As Integer)
    RaiseEvent rsaMessage(txtOwner.Text)
End Sub
0
 
LVL 5

Expert Comment

by:gary_j
ID: 11856229
put a text box on mainform called txtowner; make its visible property false

from form rsa
            mainform.txtowner.text = txtowner.text
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Dabas
ID: 11857570
Hi BIAPRO:
Why not this simple solution?

Public Sub cmdRsa_Click()
'  ask for password on Form RSA with name in textinputbox: txtOwner
  rSa.Show vbModal
  rSa.Hide
'  here I need the value entered in form RSA
    Debug.Print rsa.txtOwner.Text
End Sub

Dabas
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11859064
That won't work Dabas.

BIAPRO stated that the rSa from has only one input box on it.  Since it is being showng modal, the only way to get back to the main form is to close it with the X.  Once that has been done, the value from the textbox gets disposed along with the form.

The value you are getting from

    Debug.Print rsa.txtOwner.Text

would be the value in the textbox placed there at design time in the IDE.




Here is how to implement what gary_j has suggested:
'------------------------------------------------------
' Main Form
'------------------------------------------------------
Private rSa As rSaForm
Public owner As String

Private Sub Form_Load()
    Set rSa = New rSaForm
End Sub

Private Sub Command1_Click()
    rSa.Show vbModal
    Debug.Print owner
End Sub

'------------------------------------------------------
' rSaForm
'------------------------------------------------------
Private Sub Form_Load()
    txtOwner.Text = ""
End Sub

Private Sub txtOwner_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        If txtOwner.Text <> "" Then
            Unload Me
        End If
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If txtOwner.Text <> "" Then
        mainForm.owner = txtOwner.Text
    Else
        Cancel = True
    End If
End Sub

Regards,

Idle_Mind
0
 
LVL 27

Expert Comment

by:Dabas
ID: 11860544
Idle_Mind:
> That won't work Dabas.
You are right.
In that case I would have programmed Form_QueryUnload to cancel the closure and hide the form instead. Then my solution would have worked, but so does yours.
What is the difference between QueryUnload and Unload anyway?

Dabas
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11860610
>> In that case I would have programmed Form_QueryUnload to cancel the closure and hide the form instead.

You would be able to get the value off the form by canceling the unload and hiding it, but this has the nasty side effect of making your main form uncloseable:

Try this simple example to see:

' Form1
Private Sub Command1_Click()
    Dim f2 As New Form2
    f2.Show vbModal
    Debug.Print f2.Text1.Text
   
    MsgBox "Try closing me now..."
   
    Unload f2
    Set f2 = Nothing
End Sub

' Form2
Private Sub Form_Unload(Cancel As Integer)
    Me.Hide
    Cancel = True
End Sub

The difference between Unload and Query_Unload is that the second tells you how the application is being closed.

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

The unloadmode argument returns the following values:

Constant Value Description
vbFormControlMenu - 0   The user chose the Close command from the Control menu on the form.
vbFormCode            - 1   The Unload statement is invoked from code.
vbAppWindows        - 2   The current Microsoft Windows operating environment session is ending.
vbAppTaskManager  - 3   The Microsoft Windows Task Manager is closing the application.
vbFormMDIForm      - 4   An MDI child form is closing because the MDI form is closing.
vbFormOwner         - 5   A form is closing because its owner is closing.

For instance if you wanted to cancel the closing of the form only if the X is clicked on the form you can check for the vbFormControlMenu constant.

Or, you could only allow the operating system to close the app by checking for the vbAppWindows and vbAppTaskManager constants.

Regards,

Idle_Mind
0
 
LVL 27

Expert Comment

by:Dabas
ID: 11860811
Ta
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

916 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