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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where and how do I declare a public a variable to pass between forms 3

Status
Not open for further replies.

rew2009

Technical User
Apr 21, 2009
114
US
I am opening up a mainform “frmMAIN” that will have command buttons to open a popup form “frmSECOND” and “frmTHIRD” and several others. I want to declare a public variable “strA1” that can be used and passed between the various popup forms. Where do I declare this variable? At this point I am only familiar with using the event handling sections of the vb code (such as in the command buttons and “on click” or “on open” etc of the form objects”) so if the public variables are declared elsewhere I would need to be pointed in the right direction. I tried putting it in the declaration section of the “frmMAIN” under
__________________
Option Compare Database
Public strA1
___________________

And then tried to define “strA1” in the “on open” event:

Private Sub Form_Open(Cancel As Integer)
Dim strA1 As String
strA1 = "City"
Me.Text20.VALUE = strA1

End Sub

but it only worked in the “frmMAIN” and did not pass to the popup forms “frmSECOND”.

So where do I put it and is this the right syntax?

Thanks
 
I apologize for the confusion. I should proof my posts better. I was pulled away from the computer by my daughter who wanted me to read her a bedtime story and I sent the post without proofing it. The text35 was actually text20 in the program and should have worked. I am beginning to think this is a lost cause and maybe look at a different way to skin the cat. In my old dBase days I sometimes would have a separate table called "misc" with one record in it with a number of fields that I could store info independent of the main client tables, I could probably do something like that here. But I am sure that there is something minor that I am overlooking and that global method should work. Anyway, does anyone know if one can reverse the :

Me.Text20.VALUE = Forms!frmMAIN.strA1

And go backwards from the second form and reset the strA1 in the second form and reflect the new value in the first form. I tried this:

Forms!frmMain.strA1 = Me.Text20.VALUE

But it did not seem to work going backwards.

I do appreciate all the help

Thanks
 
But it did not seem to work going backwards
Why using global variable at all if you have a TextBox to hold the value ?
Replave this:
Forms!frmMain.strA1 = Me.Text20.Value
with something like this:
Forms!frmMain![name of control] = Me!Text20

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
rew2009 . . .

I've been waiting for the thread to settle down ... I'm giving you one thing ... [blue]PHV[/blue] is giving you another! Just be aware: the global I present can't fail!

If your willing to continue ... I'm here. I can get you thru this ... hands down!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan, after reading your offer to stick with me as my frustration levels were rising, I went back to try it again in the simplest method that I could. I created a simple two form database and on each form I had a text box and then realized that I needed two command buttons on each form, one to set the variable strA1 to its text box value and one to set its textbox to strA1 because it was unbound. And it worked going back and forth between the forms!!

I determined that the error that I had made when trying it within my application was that I was expecting that after I had changed the strA1 value on the subform that it would automatically appear in the text box in the main form as do other text boxes that are controlled (bound) by records that can be changed elsewhere. This of course is not the case with this unbound text box that had to be manually set to reflect the strA1 value.

I knew you had to be right and that I was overlooking something but sometimes you can’t see it even when it is staring you in the face. It was a more a logic error and not a sytax error. Thank you for your help. Now I know how to do it. And thanks to the rest of the group and PHV, your method also works but I wanted to be able to use the Public global method as this was something I had used successfully in my dBase days.
 
Howdy rew2009 . . .

I'm so relieved we didn't run you away from the thread! Particularly for something so eeeeeasy. I was worried about this! I didn't intend the thread to leave you in an ugly unresolved state ... nor did [blue]PHV![/blue] Now that you have it ... keep this in mind:
TheAceMan1 said:
[blue]A global variable is simply a placeholder of a value that the rest of the system an access ... on a read/write basis. Its no different then hitting the store button on a hand held calculator! Any transfers of value have to be done by you! ... Like when you restore the value held in a hand held calculator![/blue]

With that ... all I can say is ... [blue]Stay with Tek-Tips ... we are the best![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1, I knew it had to be easy and that it was something that I was doing wrong in applying your solution in my application. Global variables was something that I used regularly in dBase and was only frustrated that I couldn’t figure out how to use it in Access. I know Tek-tips is the best. You guys have helped me through many thorny problems as I have continued to improve my application. I may be posting on Tek-tips a little less in the future but only because my application is finally in a form that is usable by me and my associates. We are now using it our business and this week I spent more time on using it than programming it. But as a programmer at heart, I continue to see ways that I want to improve it and Tek-tips is the only way. I really like the fact that there are so many very qualified people posting on Tek-tips who are willing to share their knowledge to help those people like me who are converting to access and vb from other languages and platforms and really need help. I like to see different ways to skin the cat.

Along those lines I just started a new thread as I am trying to see how to close a popup form and be able to have it look the same after reopening. Any help will be appreciated. Thanks again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top