Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OK button clicked, send result to another form?

Status
Not open for further replies.

demoniac

Programmer
Jun 14, 2001
63
US
Hello :) What I'm wanting to do is have two buttons on my form (which I have). The OK button and a Back button. If they click back it just takes them to the previous form, that's working. If they click OK, I want it to set a variable to true or something so that a different form can realize that they clicked OK.

Can someone help me? :eek:)

Thanks,
demoniac
 
You may create an invisible label box in the form that you want to load and change it's caption when ok clicked.
for example

Code:
Privare Sub OKButton_Click()
    Load NextForm
    NextForm.Label1.Caption = "OKClicked"
    NextForm.Show
    Unload Me
End Sub

in the load procedure of NextForm you may check the caption of Label1 like:

Code:
Private Sub NextForm_Load()
    If Label1.Caption = "OKClicked" Then
         'Do whatever you want
    End If
End Sub

I'll be happy if it works. If you think i've misunderstand the situation, you tell more detailed and i'll try to help again.

Good Luck!

Ali INAL
Dogus University
Industrial Engineering
 
I don't know why you have to add a label to the form.

Define a variable in a module and declare it Public so all the forms in the programm can refer to.
(or if you don't have a module declare it on your first form to show)

ex:

Public intOkClicked as integer

On your click event of your OK button, set your variable to what you want

ex: intOkClicked = 1

Somewhere in your other form you just verify the value of the variable.

Make sure you have a condition that's put the variable to 0 when you don't whant the form to think that OK was clik
For instance, when they click BACK the variable is set to 0...

I do that a lot in my program when i want to know which button open my form...
 
To augment what melginger recommended, I'd say the cleanest way is to public that variable in the form that has the ok button. If that form's name is frmOk, use this to check for it:

If frmOk.OkClicked = 1 Then
'Ok was clicked
End If

Good luck!

-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
It's ok aliinal, I was doing exactly the same thing as you before I learned how to work with variable...

Thanks MikeCox, I'm new at VB (6 months!! but 3 management's applications). I learned it by myself so that's a lot of things that i don't know, for instance, about declaration of variable... But I understand my mistake... I usely declare them in a Module...




 
This is another variation on the theme How to pass a variable from one form to another. It seems to be the most popular question in this forum: It has been answered countless times, most recently cfr: thread222-112956.

Comprehensive discussions for this question can be found at thread222-37333 and / or faq222-400. I urge you to have a look at all three above references for pro and contra of different solutions.

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top