Hi. Here's a couple of potential examples where you might often see Nz() used. If you need to open a second form to show the details about the current record, the usual approach might look something like this:well these are good explanations you guys. I have used IIF() on many occassions, so i spose that's a substitute for NZ. I've also prolly logged hundreds of thousands of lines of VBA code at this point, and I'm positive I've also written substitutions for NZ in code although nothing specific comes to mind right off the bat.
DoCmd.OpenForm "FormName", , , "ID=" & Me.ID
Dim UnitPrice As Currency
UnitPrice = DLookup("Price","tblProducts","ProductID=" & Me.ProductID)
Well, almost anything available to us have strengths and weaknesses. You just need to know when to use which ones based on the situation. In addition, Access also gives us more than one way to accomplish the same thing. So, it sometimes boils down to personal taste. Just my 2 cents...sure it makes sense. that's a good post dbGuy. Regarding dlookup() though, that function just sucks. everyone says it's incredibly slow too. I don't believe I've used that very much.
cuz i'm not a fan of messing with data at the table level.Why would you consider data macros stupid?
Data macros don't only help when a change is done at the table level. Let's say you have a form for the user to use; however, let's say you, as a developer, needed to run a batch query to do a one-time update to a lot of records at the same time. In this case, it might be good to have a data macro, if possible, because you're not using a form in this situation.cuz i'm not a fan of messing with data at the table level.
that doesn't even make sense! redundancy in there!WHERE Nz(fieldname,0) = 0
This comment was about setting the 'alternative' value for null using the Nz function.that doesn't even make sense! redundancy in there!![]()
LOL. This goes back to your original question of why the Nz() function is so popular with access developers. To us, Access developers, that WHERE clause from Galaxiom makes perfect sense. You can actually replace 0 with any other value.that doesn't even make sense! redundancy in there!![]()
...WHERE Nz(Field,"Anything")="Anything"
I actually agree and try to. I just purposely didn't do it in the earlier examples to keep the topic discussion brief and concentrated on whether to use it or not - and not necessarily on the how. Cheers!Probably best practice to specify a value.
maybe I'm more of a web developer than a database dev? soon i'll be developing my first mobile app for android. so before i know it my nickname will be "swifty".LOL. This goes back to your original question of why the Nz() function is so popular with access developers. To us, Access developers, that WHERE clause from Galaxiom makes perfect sense. You can actually replace 0 with any other value.
Code:...WHERE Nz(Field,"Anything")="Anything"