passing parameters

  • Thread starter Thread starter GSteven
  • Start date Start date
G

GSteven

I'm missing something. Fairly new to Access and trying to build a selection
application. I'm presenting a list of customers in a continuous form
"ChooseCust". This list includes some information that would allow a user to
place a check in a checkbox if they want that customer on a report
"CustReport". I also wanted the user to select which salesperson was to
follow up with the chosen customers.

The first part I have working OK. The checkbox is tied back to a yes/no
field in the underlying table and when the "preview report" button is
clicked the report is called up with just the checked customers. The problem
I'm having is how to get the desired salesperson's name on the report. I'm
presenting the list of sales people in a combo box with row source tied to a
query "AllSalesPeople". I have a procedure for "after update" which then
assigns the value chosen to a public var named strSPerson. This var is
declred public in the declarations section of the form. Question is how do I
get this value passed to the report. I can step through the code (using
debug) and verify that the strSPerson is actually being assigned the correct
chosen value but as soon as I step 'out' of the procedure the var strSPerson
becomes null again. Needless to say I cannot "see" this variable from the
report when it is opened.

Can any of you experts see where I'm going wrong?

tia
Steve
 
Ho Steve
Declare strSPerson as Global in a Module, and than you
wont lose the value after you close the form. and you can
use it on the report.
When you declare A variable on the form you can ue it only
in the form.
 
OK, so I create a new module called "InitSPerson" and declare strSPerson
global (Global strSPerson as String). So then I can 'call' this proc by
asigning it to the 'on open' event of the form, right? At least that's where
my thinking leads me. So I don't see a way to 'call' the InitSPerson module.
I feel like such a newbie.

Steve
 
1. You declared strSPerson as Global
2. After you update the name of the saleperson assign that
name to strSPerson that you declared
3. On the print property of the report assign tha value of
strSPerson to the field on the report.
or create a function that return the value of strSPerson
and on controlsource of the field on the report write =
and the name of the function you created
 
Thank you very much for your replies.

OK, I place a textbox on my report and set control source to "strSPerson" or
"=strSPerson" and when I run report I get a dialog asking for strSPerson.

Decide on second suggestion. Go to module tab of database and click 'new'.
Name module 'GetSP' and contains the lines 'compare database'. 'Public
function GetSP(salper as string)', 'salper = InitSPerson.strSPerson' & 'End
Function'.
Now I cannot see the function in the builder dialog box therefore cannot
choose the function.

???
 
You mixed it up
lets try one way:

1. declared strSPerson as Global variable (You did that)
2. After you update the name of the saleperson assign that
name to strSPerson Variable that you declared (Check with
the Debuger that the variable has the value)
3. create a function that return the value of strSPerson

Function GlobstrSPerson() as string
'***************************************************
' This function will return the Name of the sales man
'***************************************************
GlobstrSPerson = strSPerson
end Function

4. On control source of the field on the report write:
"=GlobstrSPerson()"
 
see below


1. declared strSPerson as Global variable (You did that) (Yes,
successfully)

2. After you update the name of the saleperson assign that name to
strSPerson Variable that you declared (Check with the Debuger that the
variable has the value) (debugger shows value was assigned to strSPerson as
string type under InitSPerson context)

3. create a function that return the value of strSPerson

Function GlobstrSPerson() as string
'***************************************************
' This function will return the Name of the sales man
'***************************************************
GlobstrSPerson = strSPerson
end Function

(Done exactly as described)

4. On control source of the field on the report write: "=GlobstrSPerson()"

(done, when I run report I get dialog asking for a value for GlobstrSPerson
and I can either leave it blank or enter some string. In either case when
the report comes up the field has #Name? in it.)

Furthermore when I'm in debug immediate window and enter ? GlobstrSPerson()
I get a compile error "Expected variable or procedure, not module". Does
this shed any more light on it?

thanks again for your patience
Steve
 
Ofer,

Thanks for your determination in helping me through this. I went back and
'rebuilt everything from scratch and it worked. I think I must have had a
typo I wasn't spotting or something.

Thanks again
Steve
 
Back
Top