Link to home
Start Free TrialLog in
Avatar of eshurak
eshurakFlag for United States of America

asked on

Using "Not Null" in Parameters with QueryDefs in VBA

Hello,

I'm trying to return all values with a parameter in VBA but it is not taking "Is not Null" or "*".  

Thanks

Dim qry As QueryDef
Set qry = db.QueryDefs("qryEmail")

qry.Parameters![StartDate] = Form_frmCensusTracking.StartDate
qry.Parameters![EndDate] = Form_frmCensusTracking.EndDate

If gstrRegion <> "" Then
    qry.Parameters![gstrRegion] = gstrRegion
Else
    qry.Parameters![gstrRegion] = "is not null"   '"Like " & Chr(34) & "*" & Chr(34)
End If

Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Try IsNull()
Or Not IsNull()
try changing this

qry.Parameters![gstrRegion] = "is not null"

with

qry.Parameters![gstrRegion] <> Null
If Not IsNull(qry.Parameters![gstrRegion] )...
Avatar of eshurak

ASKER

Thanks Guys, but none of these are working.

Could you show what you tried with IsNull? What happened when you did that?
Avatar of eshurak

ASKER

Cap1 - I can't use "qry.Parameters![gstrRegion] <> Null" as we are assigning qry.Parameters![gstrRegion] a value.  So it has to "=" something.
So why are you using (or attempting to use) Null?
Avatar of eshurak

ASKER

IsNull() is a function that returns true or false.  What should the argument for expression be?  It won't compile as is.
If IsNull(SomeVariable oe SomeExpression) Then...
'oe' should have been 'or'
Avatar of eshurak

ASKER

The parameter exists in the query object so it needs to have something assigned to it.  Most of the time there is a value but to search for but other times there is not.  So when gstrRegion is "", I need to search for all values.  Hence the values that are not null.  


If gstrRegion <> "" Then
    qry.Parameters![gstrRegion] = gstrRegion
Else
    qry.Parameters![gstrRegion] = "is not null"   '"Like " & Chr(34) & "*" & Chr(34)
End If
try this


qry.Parameters![gstrRegion] = "= is not null"
ASKER CERTIFIED SOLUTION
Avatar of Thomasian
Thomasian
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eshurak

ASKER

I came across this website and am using it's technique combined with Thomasian's suggestion:

http://www.fontstuff.com/access/acctut07.htm

where  tblPSA.Region=[gstrRegion] or  [tblPSA].[Region] Like [gstrRegion] Is Null;


Cap, I found that no matter what I put in value for qr.Parameter it was treated as a string so it would seach for the words "is not null" in my table.


qry.Parameters![gstrRegion] = "= is not null"
ok.. and sorry did not have the time to test..