473,467 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How To Call Form VBA Function From a Query?

9 New Member
How can a sql query call a vba function inside an open form?

The form is called "Flex2 Hospitals" and the VBA function inside it is called "TJCs".

I've tried the following syntaxes without success:

Expand|Select|Wrap|Line Numbers
  1. [Forms]![Flex2 Hospitals]!TJCs
  2.  
  3. [Form_Flex2 Hospitals].[TJCs]
For example:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Hospitals
  3. WHERE [Flex2 Hospitals].[TJCs] Like [Hospitals].[TJC]
thx
Oct 21 '13 #1
4 2191
NeoPa
32,556 Recognized Expert Moderator MVP
I've tried the following syntaxes without success:
It would help to know what that means in these circumstances.

I would expect that a function reference within SQL would expect parentheses after it :
Expand|Select|Wrap|Line Numbers
  1. Form_Flex2_Hospitals!TJCs()
If that's not right you could try posting the function code itself along with your answer to my earlier question.

PS. Your attempts all look good. You clearly understand that a function procedure from an object module cannot be referenced without the reference to the module as function procedures of standard modules can.
Oct 22 '13 #2
ADezii
8,834 Recognized Expert Expert
If the Function is 'Public' and in a Standard Code Module, it can reference an Open Form and return a Value that can be used as Criteria in a Field, as in:
Expand|Select|Wrap|Line Numbers
  1. SELECT Hospitals.ID, Hospitals.LastName, Hospitals.FirstName
  2. FROM Hospitals
  3. WHERE Hospitals.ID=fGetHospCode();
Oct 22 '13 #3
topher23
234 Recognized Expert New Member
By way of explanation...
In your first syntax version:
Expand|Select|Wrap|Line Numbers
  1. [Forms]![Flex2 Hospitals]!TJCs
your code is looking for the default collection of the Forms object, which is Controls, not code procedures, so that definitely wouldn't work.
In the second instance:
Expand|Select|Wrap|Line Numbers
  1. [Form_Flex2 Hospitals].[TJCs]
the period (.) prompts Access to look for a property of the Form_Flex2 Hospitals module. In order to specify a member of the default collection (code procedures), you do need to use NeoPa's syntax with the exclamation point (!). However, ADezii's answer provides a more standardized solution.
Oct 22 '13 #4
zmbd
5,501 Recognized Expert Moderator Expert
Post the actual function within the form.

PLEASE: Include the entire function,from header to "end function"

PLEASE: Select the posted code and format it useing the [CODE/] button.


ADezii, had that part correct in "Public" and "Standard" module. I however, suspect that that that the function is "Private" to the "Class Module" of the form; thus, unless one exposes it either by using a calculated control and refering to that control, or by declairing the function "Public" no amount of mixing nomenclature is ever going to get the function's results outside of the scope of the form.
(^-^)
Oct 28 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
1
by: muelli75 | last post by:
Hi! Im getting insane by solving a problem .... I try to define a function which uses a code-snippet from another file. My base are the codes from the great book "WebDataBase-Book by H....
2
by: Jeff Wilson | last post by:
Lots of posts explained to me how to invoke a function inside a form from another form. Unfortunately, it appears that a function inside a form can have at most 1 argument. I can create a form...
5
by: Alex | last post by:
I have a load of function names stored in a table which I want to use to decide which function to run. I can select the function name but I cannot work out how to call the function if I have the...
2
by: MLH | last post by:
I would like to call a function stored in a form module in Access 2.0 from an Access 2.0 procedure in a global module. Function EmailTheOutletters () in module AppSpecific... .... 560 SSNtext...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
1
by: keith.walter | last post by:
My first asp.net app is almost "done" and I am stuck. Here is my situation: I have a "mother" page add_customer.aspx and a"child" user control add_group.ascx. On the mother page is an "add...
4
by: Martijn Mulder | last post by:
I have a menu option 'Open...' that opens an OpenFileDialog to select an image file to open. Than I need to call Form.Invalidate() to clear the Form and display the image. This happens in a...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
0
by: larryoliver | last post by:
PHP form function works on my home server. When uploaded to clients' SSL/TLS yahoo server the form function react appropriately but does not send out the emails. The contact page is: ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.