Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
171 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

670 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