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
161 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

11 Experts available now in Live!

Get 1:1 Help Now