Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Records Omitted from Query for Errors in Criteria Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tatakau - 15 Nov 2005 20:05 GMT
I have several rather complicated queries that are used for mail merges that
use functions as their fields.

ex:   Field~     Tour Time:  IIF(Format([time],"h:mm AM/PM")="12:00
PM","12:00 Noon",Format([time],"h:mm AM/PM"))

However, if by chance the value of [time] is null for a given record, it
will cause an error in the code (internal - nothing visible;
format(null,"h:mm AM/PM") doesn't go over very well), and because of this, it
will not show up in the query results.  I could fix this by doing the
following:

ex:   Field~     Tour Time:  IIF(isnull([time]),"",IIF(Format([time],"h:mm
AM/PM")="12:00 PM","12:00 Noon",Format([time],"h:mm AM/PM")))

but then I would have to go over every single one of my queries and
painstakingly edit every individual query field that uses a function.  Which
would just be a pain in the a.s.

So, I was wondering if someone could sorta do it for me.  $5 per hour.  lol,
not really, but it'd be nice if I could make the Jet engine just ignore
errors alltogether in a query.  If it can't exceute a function because of a
null value in a table, why omit the entire record?  I'd like to do something
like "On Error Resume Next", but this isn't exactly VBA.  Is there something
similar I could do?

Thanks!

Nick
Ofer - 15 Nov 2005 21:15 GMT
You can create a kind of format of your on, that can take care of the errors,
such as

Function Lib_Format(FieldValue As Variant, FieldFormat As String)
On Error GoTo Lib_Format_Err
If IsNull(FieldValue) Or FieldValue = "" Then
   Lib_Format = ""
   Exit Function
End If
Lib_Format = Format(FieldValue, FieldFormat)
Exit Function

Lib_Format_Err:
   Lib_Format = ""
End Function

And then in the query, instead of running format, run the Lib_Format
ex:   Field~     Tour Time:  IIF(Lib_Format([time],"h:mm AM/PM")="12:00
PM","12:00 Noon",Lib_Format([time],"h:mm AM/PM"))

Signature

I hope that helped
Good Luck

> I have several rather complicated queries that are used for mail merges that
> use functions as their fields.
[quoted text clipped - 25 lines]
>
> Nick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.