I'm no Access expert, and I have an (I hope!) simple question...
I have a form with a number of records. In some textboxes I just present values from the underlying table - so they are bound to the corresponding fields.
But some textboxes should contain calculated values. Some calculations are complicated and involves many fields from the table. I write the calculation as a VBA function. I could enter something like this as "Control Source":
=MyFunction([Field1], [Field2], [Field3] ...)
But I don't want to list dozens of fields in the function call. Instead, I want to send the whole form (or the current record) as a parameter, and let the function reference the fields it needs. I can do it like this:
=MyFunction([Forms]![MyForm])
But I don't like having to name the form in the call. Isn't there a way to send the "current form" as a function argument? In VBA, you just use the "Me" keyword, for exampel "Me![Field1]". But it seems like "Me" isn't accepted in an expression.
Is there some other way to reference the current form in an expression?
(It's a cosmetic question, I know. But it's not good programming to use "[Form]![MyForm]". Later on you copy the controls to another form and forget to change the name in the expression...)
Grateful for your help! :-)
/Anders
You can use:
=MyFunction([Form])
The code would be:
Function MyFunction(frm As Form)
MsgBox frm.Name
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With