473,508 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Access query shows "INVALID USE OF NULL" error when I call using VBA

66 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. MsgBox Form_frmDBC.txtProdDt.Value
  2. MsgBox Form_frmDBC.Logidas.Value
  3.  
  4. Debug.Print DLookup("[Overall]", "QryProPerc")
  5. MsgBox DLookup("[Overall]", "QryProPerc", "[ProcessorID] = '" & Form_frmDBC.Logidas.Value & "'")
My Query's SQL view is as below.

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![frmDBC]![Logidas] Text ( 255 ), [Forms]![frmDBC]![txtProdDt] DateTime;
  2. 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
  3. FROM QryPro_Npro
  4. 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]
  5. HAVING (((QryPro_Npro.ProcessorID) Like [Forms]![frmDBC]![Logidas]) AND ((QryPro_Npro.ProductionDt) Like [Forms]![frmDBC]![txtProdDt]));
Jan 26 '15 #1
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!
Jan 26 '15 #2
johny6685
66 New Member
Thanks Twinnyfo, let me try with and get back.
Jan 26 '15 #3
johny6685
66 New Member
Hi Twinnyfo, I have quick question here, Please confirm how to call the variable in Query?
Jan 26 '15 #4
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.
Jan 26 '15 #5
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:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public gstrMyText as String
  5.  
  6. Public Function GetMyText()
  7.     GetMyText = gstrMyText
  8. End Function
Then, in your forms:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtMyText_AfterUpdate()
  2.     gstrMyText = Me.txtMyText
  3. End Sub
In your query:

Expand|Select|Wrap|Line Numbers
  1. SELECT GetMyText() AS MyTextValue ...
This is where a TempVars might be more useful.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtMyText_AfterUpdate()
  2.     TempVars.Add "MyTextString", Me.txtMyText.Value
  3. End Sub
and then in your query:

Expand|Select|Wrap|Line Numbers
  1. 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!
Jan 26 '15 #6
johny6685
66 New Member
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.
Jan 26 '15 #7
johny6685
66 New Member
hi Twinnyfo, I will try this one
Jan 26 '15 #8
johny6685
66 New Member
Thanks Twinnyfo, I tried declaring the global variable and it worked.. thanks Bro... :-)
Jan 26 '15 #9
twinnyfo
3,653 Recognized Expert Moderator Specialist
Glad I could be of some help!
Jan 27 '15 #10

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

Similar topics

0
5263
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...
1
1418
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...
0
952
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...
1
9637
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...
4
4830
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...
1
5459
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...
0
3018
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...
1
1599
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.,...
1
9804
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: ...
4
6918
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...
0
7229
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
7333
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,...
0
7398
jinu1996
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...
0
7502
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
5637
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
4716
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
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...

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.