[AccessD] How do I pass a control to a function in the ControlSource

ASkolits askolits at nni.com
Tue Sep 29 16:41:47 CDT 2009


I'll let you know. Thanks.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Tuesday, September 29, 2009 5:16 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] How do I pass a control to a function in the
ControlSource

John, I can probably dig out an answer for this for you - it is based on
OnKey and Keyevents.

However I am about to go off to bed (I am in the UK and my milk is boiling
over). If you get an answer before tomorrow, please post the fact.

If not I will dig it out for you. My feeling is that you are just trying to
improve on  bunch of similar code and I can help you with that but not just
now.


Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of ASkolits
Sent: 29 September 2009 22:09
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] How do I pass a control to a function in the
ControlSource

A person enters a value in a text box and if it's within tolerance, the text
box next to it returns a Pass Or Fail.

DataEntryBoxName: txtEntry01

ResultsBox: txtEntryResult01
ControlSource: =iif(([txtEntry01] > 10) AND ([txtEntry01] <
12),"PASS","FAIL")

If you place that formula in the ControlSource, it calculates on the fly
without having to use an event.

But what if you have 100 different text boxes and result boxes (txtEntry01,
txtEntry02, txtEntry03...)
I'd have to change the control source of every result box with the proper
control names.
ControlSource: =iif(([txtEntry01] > 10) AND ([txtEntry01] <
12),"PASS","FAIL")
ControlSource: =iif(([txtEntry02] > 10) AND ([txtEntry02] <
12),"PASS","FAIL")
ControlSource: =iif(([txtEntry03] > 10) AND ([txtEntry03] <
12),"PASS","FAIL")
ControlSource: =iif(([txtEntry04] > 10) AND ([txtEntry04] <
12),"PASS","FAIL")
Etc...

But If I had a function call on the ControlSource that gave me the calling
control's name, I could one control source.
(Note: In this function, I use the last two characters of the calling
control number to find the 'data entry' text box name.)

ControlName: txtEntryResult01
ControlSource: =GetResult(ThisControl)


Function GetResult(ctrl as control)

Dim strDataEntryBox as string

'Get Data Entry Text Box Name
strDataEntryBox = "txtEntry" & right(ctrl.name,2)

	if me(strDataEntryBox) > 10 and me(strDataEntryBox) < 12 then
		GetResult="Pass"
	Else
		GetResult="FAIL"
	End if

End 

There are a bunch of way to do this. I could always use the AfterUpdate
event on each Data entry text box, but would also have to enumerate through
every control each time the form opens to refresh the results box.

I'm just trying to cut down on all the work necessary to maintain all those
different ControlSources when they essentially do the same thing.

JOhn







-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: Tuesday, September 29, 2009 4:37 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] How do I pass a control to a function in the
ControlSource

Where are you trying to send it from?  The control is a member of the
form's controls collection, so if you pass the control, it knows the
form that's its parent.  What you may be running into is the fact that
controls have specific properties and methods depending on the type of
control, but a simple control object has very few generic properties and
methods.

Why are you using properties sheet syntax for this?  It allows for
"light-weight" forms and creates nightmares for debugging.

Charlotte Foust

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Skolits
Sent: Tuesday, September 29, 2009 1:13 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] How do I pass a control to a function in the
ControlSource

I want to send a control object to a function from the ControlSource of
a text box.

I can send the Form object, but how about the control?

 

.

Example:
Let's say I want to send a control's tag to a function The name of the
control is "txtFinalCalculation", This in fact does work:
=GetTestResults([txtFinalCalculation].Tag)

The function retrieves the tag value with a function like: 
Function GetTestResults(strTagValue as string)

But I had to include the control's name in the original call. I want it
generic.

Something like:
=GetTestResults(ThisControl)

Then use the following function:
Function GetTestResults(ctlControl as control)

I've tried some things with "Active control " but that won't work.
There has to be a way to send the control's info to a function.
I can send the Form's properties: GetTestResults([Form]), but I want
just the individual control.

 

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list