Marcus:
This is probably a little more than what you asked for, but here's my
philosophy. (If you disagree with my, be gentle ... I'm just getting back
into posting at newsgroups after a long absence :-)
First, the simple answer and suggestion for your code. Check for nulls
and branch to a different SQL script depending on what the value is.
If IsNull([Forms]![frmSelect]![cboDate]) Then
strSQL = "SELECT * FROM tblData WHERE 1=1 AND strCriteria & ");"
Else
strSQL = "SELECT * FROM tblData WHERE tblData.Date = #" & _
[Forms]![frmSelect]![cboDate] & " AND strCriteria & ");"
End If
Now, the long answer.
I don't like referencing form controls in queries for two reasons:
1) The form might not be open, which fails quite ungracefully
2) You cannot easily do what you describe, substitute for NULLs
Here's the process I have been using lately:
1) Create a function that retrieves a value from a form
2) Handle all errors and missing data in the function
3) Use the function in the WHERE clause of the query.
It works something like this ...
Public Function GetFormDate() As Date
On Error Resume Next
Dim varValue As Variant
If IsLoaded("frmYourForm") Then
varValue = Forms!frmYourForm!txtDate
If IsNull(varValue) Or Not IsDate(varValue) Then
varValue = #12-31-1959#
End If
GetFormDate = varValue
Else
' insert bogus default data ... probably won't match anything
GetFormDate = #12-31-1959#
End If
End Function
Your Query now becomes ...
strSQL = "SELECT * FROM tblData WHERE tblData.Date = #" & _
GetFormDate() & "# AND " & strCriteria
If you're clever, you can return a String from this function and use
the LIKE operator to return ALL records by passing the wildcard char.
--
Danny J. Lesandrini
dl*********@hotmail.com www.amazecreations.com/datafast
"Marcus" <to*******@yahoo.ca> wrote ...
Wondering if it's possible to allow for Null enteries in SQL/VB code.
The example below doesn't work. Am I missing something? Or, is this
just not possible?
strSQL = "SELECT * FROM tblData " & _
"WHERE " & "tblData.Date = #" & [Forms]![frmSelect]![cboDate]
& " Or (" & [Forms]![frmSelect]![cboDate] Is Null & ")# AND (" &
strCriteria & ");"
Marcus
******
--
Danny J. Lesandrini
dl*********@hotmail.com
www.amazecreations.com/datafast/
"Marcus" <to*******@yahoo.ca> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
Wondering if it's possible to allow for Null enteries in SQL/VB code.
The example below doesn't work. Am I missing something? Or, is this
just not possible?
strSQL = "SELECT * FROM tblData " & _
"WHERE " & "tblData.Date = #" & [Forms]![frmSelect]![cboDate]
& " Or (" & [Forms]![frmSelect]![cboDate] Is Null & ")# AND (" &
strCriteria & ");"
Marcus
******