[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

Function as control source for unbound field

I'm just experimenting with this, trying to see if I can put the name of a vba function as the control source for a form field.    The function detects and uses the value of another field on the form.  

I haven't been able to get this to work.  Is it possible?  Any links that would help?

Thanks!
0
codequest
Asked:
codequest
  • 4
  • 3
  • 2
  • +1
5 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Control Source:

=YourFunctionName()

don't for get equals sign and parens.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
And be sure you have a Function, not a Sub ...

mx
0
 
mbizupCommented:
= yourFunctionName(txtbox1, txtbox2)

 Be sure to include the =  sign and leave out the Me prefix which is applicable to VBA but will cause problems in form and control properties such as a controlsource.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
IrogSintaCommented:
Be sure that your function is also set to return a value.  And if your function is in a module then make sure it is declared as Public.

Public Function NameOfFunction(strTemp As String) As String   '(or As Integer, Long, Double etc..)
    .. 
    ..
    NameOfFunction = valueToPassBackToCaller
End Function

Open in new window

0
 
codequestAuthor Commented:
Thanks for inputs.  I got it to work with a "Single" form.  Is there some problem with using it for a "Continuous" form?
0
 
mbizupCommented:
Unbound controls appear the same and hold the same value in all records.

This is most apparent in a continuous form setup where all records are grouped together (you will see the same value in all records)
0
 
mbizupCommented:
A workaround is to add that function as a field in a query, base your form's recordsource on that query and use the calculated field for your control source.

What is the function you are using?
0
 
mbizupCommented:
You may also be able to get around this by passing values to your function like this:

= yourFunctionName(txtbox1, txtbox2)

instead of using form references in the function itself.
0
 
codequestAuthor Commented:
Thanks for input.  I'll need some time to think about it and try some things.
0
 
codequestAuthor Commented:
All inputs were useful in helping with the solution, which has now going whizzing into the past...
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now