I have a question about the nz() function. When the first record is null in the database, we can use nz() function to let the receiptNumber =0. I use this code, RMax=Nz(DMax('ReceiptNumber", "tblReceipt"))+1, it works in my old pc. For the first record, it did get 1 for RMax, But for the other PC, it didn't get the 1, How can i handle the null value. I tried RMax=Nz(DMax('ReceiptNumber", "tblReceipt"),0)+1. It still didn't get the 1 for the first record. Thanks.
It is (in my opinion) a good idea to tell the Nz() function what to Return if Null is encountered. And again in your case this would be 0.
It is (again in my opinion) good practice to use the square brackets around Field and Table names when used in code or SQL strings and if not only for the reason that there may come a time when one of your Field Or Table names are not one word but perhaps two...or three.
For example: "ReceiptNumber" and "Receipt Number".
Notice that the second Field name consists of two words. If entered in this fashion into the DMax() Function, the function will fail miserably and a 3075 error will occure (Syntax Error (Missing Operator) in query expression).
Now if "[Receipt Number]" was supplied to the DMax() function, all will work fine.
For Table names, you can actually get away with names containing spaces but not in all cases. It's a good idea to place the square bracket around table names with spaces as well.
The bottom line is this....if your Field or Table names contain spaces then enclose them in the square brackets [ ] when using them. A simple solution to al this is.....don't ever use names that contain spaces in them.
The reason why I made the comment in the first place is....take a real close look at your original Post....
you supplied us with:
and then you provided yet another example with:
Can you see the apostrophe (red)....within both samples?
I just simply don't like it, but then again....that's just my opinion.
Self Taught In ALL Environments.....And It Shows!