passing variables between subs

  • Thread starter Thread starter RSN
  • Start date Start date
R

RSN

I have 1 field on a subform which I want to compare 2
values on. I need to get the value when the field "gets
focus" and "after update" then compare the 2 values. I
know how to write the code within each event. In
the "after update" code, I need to pull the value returned
in the "gets focus" code so I can compare it to the new
value. I was wondering how to do this. Help please.

On a side note, I am aware of the ".OldValue" method. I
would greatly like to use it but as of yet, I have been
upable to get it to work. My first problem was the field
being on a subform. (By the way, the combo box using after
update and get focus is on the same subform). I posted
here and got a solution. So now, in the after_update sub
I have:
Dim stOldValue As String
stOldValue = Me![Field Name].OldValue
also tried:
stOldVale = Forms![Main Form Name]![Subform Name].Form!
[Field Name].OldValue

As far as I know, these both should work the same.
However, I get the lovely error, "Object doesn't support
this property or method" So I declared it as everything I
could think of. Nothing worked so I went back to what I
originally asked about, passing a value between 2 event
subs. I would be thrilled to have a working solution
either way. Thank you for any assistance you can give me.
 
To access the value from another subroutine, the easiest way would be to
store the value in a global variable.

ex.

Option Explicit
Dim strOldValue As String

private sub Control_GotFocus
strOldValue = Forms!["MainForm"]!["Subform"].Form!["MyControl"].Value
end sub

private sub Control_AfterUpdate
Dim newVal As String
newVal = Forms!["MainForm"]!["Subform"].Form!["MyControl"].Value

' now compare newVal and strOldValue
end sub

I hope I'm understanding your problem correctly and I hope this helps.
 
Back
Top