Pass field to events' function

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Pass field to events' function

Post by agibsonsw »

Hello. (Access 2003)

On a form, I'm using a function procedure for the Click event of a button. I'm trying to pass a field to the procedure: =MyFunc([LastName]) which has the declaration:
Function MyFunc(fld as Field)
It won't allow this with a Type Mismatch error. How can I pass this field to the procedure? Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78448
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pass field to events' function

Post by HansV »

A form doesn't have fields, it has controls.

If you want to pass the value of LastName, change the declaration to

Function MyFunc(fld As String)

If you want to pass LastName as a control, change the declaration to

Function MyFunc(fld As Control)
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Pass field to events' function

Post by agibsonsw »

Thank you - I should know that a form doesn't have fields..
I can pass it as a control and examine it's control source to find the field name. But having done that, I might as well pass the field name as a string anyway.
Ta, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.