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
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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