Check if a field is empty (1 Viewer)

Gr3g0ry

Registered User.
Local time
Yesterday, 22:59
Joined
Oct 12, 2017
Messages
163
quantity = me.amount.value
keeps giving me an errow when amount is empty. is there a way to check if the field is empty and return 0 instead ?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:59
Joined
Feb 19, 2002
Messages
43,275
If you want to automatically return a zero, use the Nz() function.

quantity = Nz(Me.Amount,0)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:59
Joined
Feb 28, 2001
Messages
27,186
First, just to save you future typing, you can drop the .Value reference because for anything that HAS a value, the .Value property is the default.

Second, what is the data type of the "amount" field?
 

Gr3g0ry

Registered User.
Local time
Yesterday, 22:59
Joined
Oct 12, 2017
Messages
163
First, just to save you future typing, you can drop the .Value reference because for anything that HAS a value, the .Value property is the default.

Second, what is the data type of the "amount" field?
Double ... i have another thats Integer too ... might wanna use the same technique elsewhere
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:59
Joined
Feb 28, 2001
Messages
27,186
If no JOIN is involved in the formation of that RecordSource, numeric fields can't be null. They can be zero. If the control in question is bound to a non-JOIN recordset, it can't be null either, unless somehow NO record is selected - in which case EVERY bound field would be null.

Null occurs in JOINs when a matching record is not found in the JOIN query, and for unbound controls, you can get a null if something doesn't load the control (and it doesn't have an explicit default value). But the important part is that nobody has asked the question yet, so I guess I will.

You say that you get an error when the amount is empty. What, specifically, is the error message?
 

Gr3g0ry

Registered User.
Local time
Yesterday, 22:59
Joined
Oct 12, 2017
Messages
163
If no JOIN is involved in the formation of that RecordSource, numeric fields can't be null. They can be zero. If the control in question is bound to a non-JOIN recordset, it can't be null either, unless somehow NO record is selected - in which case EVERY bound field would be null.

Null occurs in JOINs when a matching record is not found in the JOIN query, and for unbound controls, you can get a null if something doesn't load the control (and it doesn't have an explicit default value). But the important part is that nobody has asked the question yet, so I guess I will.

You say that you get an error when the amount is empty. What, specifically, is the error message?
i had discontinued that effort. i had simply resorted to change the layout of my form. the suggestion made by @Pat Hartman had helped. tyvm kind sir
 

Users who are viewing this thread

Top Bottom