Results 1 to 4 of 4
  1. #1
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17

    Use custom function in Expression Builder

    I created a custom function in a VBA module. How do I now use that function for a table column that is type "Calculated". All the tutorials online seem to show the custom functions as magically showing up in the "Expression Builder" window, but mine is not listed there.

  2. #2
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    Nevermind. I'll just call the function from a query. Man.....Access is frustrating.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Which tutorials? It is documented that you can't use custom functions in a calculated field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    I personally would not use a calculated field. There are many reasons but one is migrating backends and the host db architecture does not like it. Instead of using a calculated field just leave the attribute name (i.e. column) the same and change the data type to whatever data it will be holding (i.e. integer). Now set that text box's [Event Procedure] on GotFocus() by selecting it on the form. Open VBA editor for that GotFocus [Event Procedure] and type out the code. Here is example.

    Private Sub txtCalculatedTextBox_GotFocus()
    Me!txtCalculatedTextBox = ((txtValueTextBox1 + txtValueTextBox2) * txtValueTextBox3)
    End Sub

    Now every time the field is clicked it will automatically calculate based on the values of those fields (assuming you already entered all of those values first) and yet your table attribute can be a standard data type compatible with most database architectures. It will work like a charm every time. Note: if you are driving for a custom function then possibly set the calculated attribute data type to text (i.e. string) instead of integer.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2016, 01:51 PM
  2. Expression Builder - Function DateDiff
    By geraldk in forum Access
    Replies: 2
    Last Post: 04-01-2015, 12:08 PM
  3. iff function in expression builder
    By deso in forum Queries
    Replies: 4
    Last Post: 03-21-2013, 11:20 PM
  4. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  5. IIf Function for expression builder
    By Bertrand82 in forum Programming
    Replies: 3
    Last Post: 11-12-2012, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums