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

passing public variables

Status
Not open for further replies.
Sep 6, 2007
11
US
I'm into one of the subforms that will be using the public variable from the main form and am not having success passing the data from the main form over. on the subform, i created a textbox (txt_currentyear) w/ this in the control source field: =[WrkYear] & " Golf Outing"

WrkYear was the defined in a module as:
**********
Option Compare Database
Option Explicit

Public WrkYear As String
**********

I have created a listbox w/ a few years as the values in the mainform (current_year_listbox). this has =[WrkYear]=Me.Current_Year_listbox.Value in the after update field. i loaded the main form, selected the year, went into the subform to see if it passed the data along w/ no luck.

do i need to call or reference that module in every form or report before i can use the data from it? right now, i just get an empty field on the subform.
 
I just tried this and set the control source of a text box in the subform to:
=[Parent].[wrkyear]
I needed to add code in to Refresh the subform in order for the value to appear in the subform's text box.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
you literally typed =[Parent].[wrkyear] in then? or does [Parent] reference my module location/name?

when u added the code to refresh the subform/form, is that in the Private Sub Form_Current() ?
 
I provided the exact control source of the text box on my subform. wrkyear is the public memory variable declared like you declared yours. [Parent] references the form object containing the subform.

For testing purposes, I added a command button on the subform with code of:
Code:
   Me.Refresh

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
When I can't figure out or remember the syntax for something, I'll use the debugger to figure it out. For example, place a button on the subform and in the OnClick event enter the word Stop. When the button is clicked the program will stop at the stop statement. Then view the Watch window (or Immediate window) and add to the Watch the word Me. You will then be able to expand it to see all of the properties, variables, etc.
 
i may have described what i was doing incorrectly. i do have multiple forms. one of them i named main and the others i named subforms. now is there a difference in creating a subform vs. creating multiple forms and just having my main form open them up? will that affect the above instructions you gave me?
 
This will definitely change the code. A "subform" is always used to refer to a form that is embedded on a main form.

You may be able replace [Parent] with the form name like
=Forms.YourFormName.[wrkyear]


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top