MS Access query shows "INVALID USE OF NULL" error when I call using VBA, but when I run directly it works.
I tried calling the parameters value i.e. form field value before calling the query, it shows the correct data, but not sure why the error pops up. Please help me to debug. - MsgBox Form_frmDBC.txtProdDt.Value
-
MsgBox Form_frmDBC.Logidas.Value
-
-
Debug.Print DLookup("[Overall]", "QryProPerc")
-
MsgBox DLookup("[Overall]", "QryProPerc", "[ProcessorID] = '" & Form_frmDBC.Logidas.Value & "'")
My Query's SQL view is as below. - PARAMETERS [Forms]![frmDBC]![Logidas] Text ( 255 ), [Forms]![frmDBC]![txtProdDt] DateTime;
-
SELECT QryPro_Npro.ProcessorID, QryPro_Npro.ProductionDt, TimeValue(Format(([QryPro_Npro].[Productive]),"hh:nn:ss"))/TimeValue("08:00:00") AS Productive, TimeValue(Format(([QryPro_Npro].[Non-Productive]),"hh:nn:ss"))/TimeValue("08:00:00") AS NonProductive, TimeValue(Format(([QryPro_Npro].[Overall Time Spent]),"hh:nn:ss"))/TimeValue("08:00:00") AS Overall, 1-[Productive] AS ProdBalTime, 1-[QryPro_Npro].[Non-Productive] AS NPBalTime, 1-[QryPro_Npro].[Overall Time Spent] AS OABalTime
-
FROM QryPro_Npro
-
GROUP BY QryPro_Npro.ProcessorID, QryPro_Npro.ProductionDt, TimeValue(Format(([QryPro_Npro].[Productive]),"hh:nn:ss"))/TimeValue("08:00:00"), TimeValue(Format(([QryPro_Npro].[Non-Productive]),"hh:nn:ss"))/TimeValue("08:00:00"), TimeValue(Format(([QryPro_Npro].[Overall Time Spent]),"hh:nn:ss"))/TimeValue("08:00:00"), 1-[Productive], 1-[QryPro_Npro].[Non-Productive], 1-[QryPro_Npro].[Overall Time Spent]
-
HAVING (((QryPro_Npro.ProcessorID) Like [Forms]![frmDBC]![Logidas]) AND ((QryPro_Npro.ProductionDt) Like [Forms]![frmDBC]![txtProdDt]));
9 2233 twinnyfo 3,653
Recognized Expert Moderator Specialist
johny,
For whatever reason, Access is not a fan of using references to Forms when it calls Queries in VBA (I've run across your same error!).
One way to do it is to gather the values on the form using variable in your procedure first, then create the query using those variables. Another is to use global variables, which are assigned when the values on the form are updated. You could also make use of the TempVars variables, which have some usefulness in such situations.
Hope this hepps!
Thanks Twinnyfo, let me try with and get back.
Hi Twinnyfo, I have quick question here, Please confirm how to call the variable in Query?
NeoPa 32,557
Recognized Expert Moderator MVP
Have you checked references in the SQL to the parameters? Is there any such reference which would fail if it were replaced by Null?
If so then that is an error and needs to be rectified. Failing isn't aberrant behaviour at all but exactly how it's supposed to work.
twinnyfo 3,653
Recognized Expert Moderator Specialist
If you have a Global Variable, the only way to use it in a Query is to also create a Public Function that calls it. Example:
Public Standalone Module: - Option Compare Database
-
Option Explicit
-
-
Public gstrMyText as String
-
-
Public Function GetMyText()
-
GetMyText = gstrMyText
-
End Function
Then, in your forms: - Private Sub txtMyText_AfterUpdate()
-
gstrMyText = Me.txtMyText
-
End Sub
In your query: - SELECT GetMyText() AS MyTextValue ...
This is where a TempVars might be more useful. - Private Sub txtMyText_AfterUpdate()
-
TempVars.Add "MyTextString", Me.txtMyText.Value
-
End Sub
and then in your query: - SELECT TempVars("MyTextString") AS MyTextValue ...
You must be sure to use the .Value property of your Controls, as TempVars (for some reason) wants to assign the control itself to your variable if not.
Hope this hepps!
Yes NeoPa, i check before the query executes the parameters does have the values but don't know how it gets nul value while executes.
hi Twinnyfo, I will try this one
Thanks Twinnyfo, I tried declaring the global variable and it worked.. thanks Bro... :-)
twinnyfo 3,653
Recognized Expert Moderator Specialist
Glad I could be of some help!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mara |
last post by:
Hi,
I have very serious problem with query in Access.
I have, in my DB, a lot of forms with some buttons that I use to do
query.
When I press that buttons and query start I have "Invalid...
|
by: Wayne Aprato |
last post by:
I have a couple of Access 2000 and 2002 databases which have exhibited
the following behaviour. The mdb works fine but the mde causes access
to shut down on an error when a particular query is...
|
by: Denile |
last post by:
HI...everyone
I meet a problem when I call .net assembly in ATL control. It's works
well when I call ATL Control in IE of my computer, but when I copy this ATL
Control to others computer.It's pop...
|
by: Tsair |
last post by:
Excel.ApplicationClass oxl = new Excel.ApplicationClass();
oxl.Version
The exception error message "old format or invalid type library. (Exception
from HRESULT : 0x80028018...
|
by: wqyuwss |
last post by:
Hi,
We have several core dumps in our product. These core dump can be
reproduced in the same place. That is system function call
std::basic_istream<char,std::char_traits<char>>::getline. The...
| |
by: suslikovich |
last post by:
Hi all,
I am getting this error when insert values from one table to another in
the first table the values are varchar (10). In the second they are
datetime. The format of the data is mm/dd/yyyy...
|
by: jtsl |
last post by:
I have a project where I need to save the form details into Ms Access database. Form consists of text box, select box, and files selection to upload to a table in the database.
In understood that in...
|
by: AccessBeetle |
last post by:
SELECT DISTINCT .Contact1Index, Contacts., Contacts., Contacts., Contacts., Contacts.prefix, Contacts.Suffix, Contacts., Contacts., Contacts.city, Contacts.state, Contacts.zip, ., tblStatusCloseout.,...
|
by: janiecarter |
last post by:
Hi all,
I have a query called and I want to rank each customer grouped on the field and then by descending order on .
I have found many solutions where I can use a subquery to do this eg:
...
|
by: peter Lu |
last post by:
Hi all I would like to remove weekend and holidays from my access query: Here is the function i'm using. I tried using a exclude 1&7 for sat and sunday but it doesn't work...
Days...
|
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,...
| |
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |