Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2003
    Location
    London
    Posts
    341

    Unanswered: Transfer Values from 1 form to another

    I have a form that I run a report from a form (Frm_Nav_Report).

    The report runs on a query which gets its conditions from drop downs on (Frm_Nav_Report). This works fine.

    ---
    --- Is it possible for me to run this report from another form? ---
    ---

    I have a form where I can scroll through the courses, and I would like to command access to report on this course using the same query.

    The idea I had was for a button, once clicked to open (frm_Nav_Report), and set the correct values.

    The problem is I don't know how to transfer the values from the first form (Frm_Courses) to (frm_Nav_Report).

    The combo list on (Frm_courses) is called (Val_TrainingCourse) and the combo list on (Frm_Nav_Report) is also called (Val_TrainingCourse).

    Can anyone help with this?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    assuming both forms are open....

    forms!frm_Nav_Report.Val_TrainingCourse = forms!frm_Courses.Val_TrainingCourse

    you can replace the form!realFormName for the form where the code is running with Me and it will run slightly faster.

    if both forms are not open, you have to save the value in a variable of suitable type that will be in scope during the life of both forms ...probably a global is easiest.

    myGlobal = forms!frm_Courses.Val_TrainingCourse 'or = me.Val_TrainingCourse
    ...and sometime later...
    forms!frm_Nav_Report.Val_TrainingCourse = myGlobal 'or me.Val_TrainingCourse =

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    Using the global setting sounds like what I need.

    I assume that in the combos I set a VB code to run AfterUpdate for this value to be set, is this correct?

    How do I use a global code?

    Below is the code I attempted to execute for the combo list of Trainers on Frm_Nav_Report, but I guess this is wrong.

    -------

    Private Sub Val_TrainingCourse_AfterUpdate()

    MyGlobal = Me.Val_TrainingCourse

    End Sub

    ------

    Another question. In the query I use, is it possible to obtain the global value?

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    get yourself to the "modules" section of the database window.
    New.
    global MyVariable as Long '...or whatever type it should be

    you can now refer to MyVariable anywhere in the application.



    you can't use MyGlobal directly in a query. still in your new global module, try:

    public function whatIsMyGlobal() as Long '...or whatever type MyVariable is
    whatIsMyGlobal = MyVariable
    exit function

    ...and you can use whatIsMyGlobal in a query as criteria etc

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    I'm sorry but I didn't understand that.

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    in access, hit the F11 key ...you see the database window. last item in the first section of the list on the left: Modules. Make a new module

    in the code window of your (mostly empty apart from Option statements if you have set options) new module, type:

    global MyVariable as Variant 'since you don't tell me what type it is
    public function whatIsMyVariable() as Variant '...since you dont etc etc
    whatIsMyVariable = MyVariable
    exit function

    save.
    done.

    you now can set & retrieve values to/from MyVariable from anywhere in your application i.e. it is a variable with global scope


    MyVariable = 6 'works on any form, and keeps it's value after the form closes

    you can use whatIsMyVariable in a query to return the value of MyVariable (you cannot use the variable directly)

    if you still don't understand, then i don't understand what it is you don't understand ...so you need to explain before i can explain.

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    EXCELLENT!!!

    Thanks for this! It works a treat now!

    Just got to go through and clean up my mess now. I really shouldn't have been doing my testing on the Live system.

    Cheers once again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •