A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIF "Add-On"



 
 
Thread Tools Display Modes
  #1  
Old September 6th, 2005, 10:34 PM
Sparky Arbuckle
external usenet poster
 
Posts: n/a
Default IIF "Add-On"

So after reading documenation and Usenet help replies this morning I
have concluded that the IIf function in Access is not going to help
with my current situation. If I understand correctly, IIf is only used
when and only when there is a field that could be null. For instance,
if there are work phone, home phone, cell phone fields in a database
and someone only has a cell phone, etc... Let's say you have a product
in tblProducts and revisions in tblRevisions. The products table has a
RecordID that ties that table to tblRevisions.

Some products have Revisions and are listed in tblRevisions while
others do not. tblRevisions has a RevNumber field that is an integer. I
retrieve this data and then set a variable intRev = to:

ds.Tables("DataTable").Rows(0)("RevNumber")

Upon doing this I get an error at runtime that reads: Cast from type
'DBNull' to type 'Integer' is not valid.

So, I guess my question is this: Is it possible to create an instance
of RevNumber with a value of 0 while executing a query if that
RevNumber / 0 doesn't exist?

  #2  
Old September 6th, 2005, 10:43 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default

Try

Nz(ds.Tables("DataTable").Rows(0)("RevNumber"),0)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Sparky Arbuckle" wrote in message
ups.com...
So after reading documenation and Usenet help replies this morning I
have concluded that the IIf function in Access is not going to help
with my current situation. If I understand correctly, IIf is only used
when and only when there is a field that could be null. For instance,
if there are work phone, home phone, cell phone fields in a database
and someone only has a cell phone, etc... Let's say you have a product
in tblProducts and revisions in tblRevisions. The products table has a
RecordID that ties that table to tblRevisions.

Some products have Revisions and are listed in tblRevisions while
others do not. tblRevisions has a RevNumber field that is an integer. I
retrieve this data and then set a variable intRev = to:

ds.Tables("DataTable").Rows(0)("RevNumber")

Upon doing this I get an error at runtime that reads: Cast from type
'DBNull' to type 'Integer' is not valid.

So, I guess my question is this: Is it possible to create an instance
of RevNumber with a value of 0 while executing a query if that
RevNumber / 0 doesn't exist?



  #3  
Old September 6th, 2005, 11:07 PM
Sparky Arbuckle
external usenet poster
 
Posts: n/a
Default

Thanks Doug. I am actually using ASP.NET and believe that NZ is VB6
function. At least I know what to start looking into. Worst case
scenario I could create a .NET function that is equivalent to NZ.

  #4  
Old September 6th, 2005, 11:25 PM
Sparky Arbuckle
external usenet poster
 
Posts: n/a
Default

My bad. I read somewhere that it was a VB6 function. Maybe it is.
Anyway, how would I incorporate it into a SQL string? Or do I need to
create some VBA?

  #5  
Old September 6th, 2005, 11:28 PM
George Nicholson
external usenet poster
 
Posts: n/a
Default

Actually, NZ is an Access function (available within Form, Report and Query
design as well as VBA). If it were VB6, it would at least be available in
Excel VBA and it isn't.

--
George Nicholson

Remove 'Junk' from return address.


"Sparky Arbuckle" wrote in message
oups.com...
Thanks Doug. I am actually using ASP.NET and believe that NZ is VB6
function. At least I know what to start looking into. Worst case
scenario I could create a .NET function that is equivalent to NZ.



  #6  
Old September 6th, 2005, 11:41 PM
Sparky Arbuckle
external usenet poster
 
Posts: n/a
Default

I fixed it!

Dim intRevNumber As Integer

If ds.Tables("DataTable").Rows(0)("RevNumber") Is DBNull.Value Then
intRevNumber = 0
Else
intRevNumber = ds.Tables("DataTable").Rows(0)("RevNumber")
End If

Return ds.Tables("DataTable").DefaultView

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.