function with variables from different forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wilder

    #1

    function with variables from different forms

    I wrote a simple funtion to automatically compute corrected azimuths
    in several places in a database but am having trouble implementing it.
    I placed the function in a module and am trying to pass to it three
    variables: magnetic declination, compass degrees and declination
    direction (east or west). The idea is that a user will enter the
    current magnetic declination and direction in a form and have those
    parameters apply to other forms (where the unique ids match).

    How do I pass the variables to the function in the module and have the
    function result passed back to the correct text box on the form?

    I tried calling the function simply by placing
    "=f_compute_tru e_magnetic([frm_sample_even t].[current_mag_dec _direction],[Me].[azimuth_magneti c],[frm_sample_even t].[current_mag_dec lination])"

    in the form load event line in the properties of my form. I also
    placed this line in the After Update event for object
    (azimuth_magnet ic) I'm trying to update on form. And it's not
    working. The "frm_sample_eve nt" is where the mag dec and direction
    are entered.

    I also tried putting the function in the code for the form and
    entering:
    azimuth_correct ed = f_compute_true_ magnetic([frm_sample_even t].[current_mag_dec _direction],
    [Me].[azimuth_magneti c], [frm_sample_even t].[current_mag_dec lination])

    in the Form Load event but I get an error when I try to open that form
    from the frm_sample_even t.

    Thanks for any help you can offer.

    Doug in Alaska
  • Larry  Linson

    #2
    Re: function with variables from different forms

    Databases are about stored data, and you didn't give us much information
    about how you've stored your data. Nor did you indicate how you wanted to
    invoke the function -- whether from code, or as the ControlSource of a
    Control or ???.

    Let's assume the former:

    In the Click event of a Command Button on the form where the arguments are
    in Controls named, txtMD, txtCD, and txtDD, call your Azi function as
    follows:

    CorrAz = Azi(Me!txtMD,Me !txtCD,Me!txtDD )

    If in Control Source, then we'll assume your form is frmF, the Control
    Source would be:

    = Azi(Forms!frmF! txtMD,Forms!frm F!txtCD,Forms!f rmF!txtDD)

    The "apply to other forms" would mean that you'd make sure the record was
    saved using Me.Dirty = False, and then Requery the other forms -- if they
    are all bound.

    I trust you aren't planning on storing redundant data that you could as
    easily calculate when you need to use or display it.

    Larry Linson
    Microsoft Access MVP



    "Wilder" <Doug_Wilder@np s.gov> wrote in message
    news:b2dc7eea.0 310101652.7114f 07@posting.goog le.com...[color=blue]
    > I wrote a simple funtion to automatically compute corrected azimuths
    > in several places in a database but am having trouble implementing it.
    > I placed the function in a module and am trying to pass to it three
    > variables: magnetic declination, compass degrees and declination
    > direction (east or west). The idea is that a user will enter the
    > current magnetic declination and direction in a form and have those
    > parameters apply to other forms (where the unique ids match).
    >
    > How do I pass the variables to the function in the module and have the
    > function result passed back to the correct text box on the form?
    >
    > I tried calling the function simply by placing
    >[/color]
    "=f_compute_tru e_magnetic([frm_sample_even t].[current_mag_dec _direction],[Me
    ].[azimuth_magneti c],[frm_sample_even t].[current_mag_dec lination])"[color=blue]
    >
    > in the form load event line in the properties of my form. I also
    > placed this line in the After Update event for object
    > (azimuth_magnet ic) I'm trying to update on form. And it's not
    > working. The "frm_sample_eve nt" is where the mag dec and direction
    > are entered.
    >
    > I also tried putting the function in the code for the form and
    > entering:
    > azimuth_correct ed =[/color]
    f_compute_true_ magnetic([frm_sample_even t].[current_mag_dec _direction],[color=blue]
    > [Me].[azimuth_magneti c], [frm_sample_even t].[current_mag_dec lination])
    >
    > in the Form Load event but I get an error when I try to open that form
    > from the frm_sample_even t.
    >
    > Thanks for any help you can offer.
    >
    > Doug in Alaska[/color]


    Comment

    • Kelly Rees-Danforth

      #3
      Re: function with variables from different forms


      "Wilder" <Doug_Wilder@np s.gov> wrote in message
      news:b2dc7eea.0 310101652.7114f 07@posting.goog le.com...[color=blue]
      > I wrote a simple funtion to automatically compute corrected azimuths
      > in several places in a database but am having trouble implementing it.
      > I placed the function in a module and am trying to pass to it three
      > variables: magnetic declination, compass degrees and declination
      > direction (east or west). The idea is that a user will enter the
      > current magnetic declination and direction in a form and have those
      > parameters apply to other forms (where the unique ids match).
      >
      > How do I pass the variables to the function in the module and have the
      > function result passed back to the correct text box on the form?
      >
      > I tried calling the function simply by placing
      >[/color]
      "=f_compute_tru e_magnetic([frm_sample_even t].[current_mag_dec _direction],[Me
      ].[azimuth_magneti c],[frm_sample_even t].[current_mag_dec lination])"[color=blue]
      >
      > in the form load event line in the properties of my form. I also
      > placed this line in the After Update event for object
      > (azimuth_magnet ic) I'm trying to update on form. And it's not
      > working. The "frm_sample_eve nt" is where the mag dec and direction
      > are entered.
      >
      > I also tried putting the function in the code for the form and
      > entering:
      > azimuth_correct ed =[/color]
      f_compute_true_ magnetic([frm_sample_even t].[current_mag_dec _direction],[color=blue]
      > [Me].[azimuth_magneti c], [frm_sample_even t].[current_mag_dec lination])
      >
      > in the Form Load event but I get an error when I try to open that form
      > from the frm_sample_even t.
      >
      > Thanks for any help you can offer.
      >
      > Doug in Alaska[/color]


      Visit the official MVP site:

      Kelly Rees-Danforth, MVP


      Comment

      Working...