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
162 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 85

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
JSON Response and request in VB6 application 11 250
VBS file using code from 2nd file (txt or vbs) 4 31
VB6 - Compare and highlight cell not the same 3 42
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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now