Solved If Not [ComboBox] Is Null Statement in VBA (1 Viewer)

bob fitz

AWF VIP
Local time
Today, 09:53
Joined
May 23, 2011
Messages
3,874
My mistake. I forgot to add And Nz(Me.textboxName,"") = "" but it still doesn't work
Are you sure? Micron is seldom, if ever wrong.
It works for me. Did you replace "textboxName" with "numberOfpsd".
 

tihmir

Registered User.
Local time
Today, 01:53
Joined
May 1, 2018
Messages
142
I dont know whats going on but this code doesnt want to work. It will completely break my nerves.
Here is the DB with the last code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not Nz(Me.cbopsdCode, "") = "" And IsNull(Me.numberOfpsd) Then
        MsgBox "Please enter the number of products!", vbInformation, "Atention!"
        Cancel = True
        Exit Sub
    End If
End Sub
Please, check it
 

Attachments

Micron

AWF VIP
Local time
Today, 04:53
Joined
Oct 20, 2018
Messages
3,206
I can't explain why the test for a ZLS doesn't work with a numeric field
Did you remove the zero default value? Like I said, it will never be null or zls when there are default values. I'll have to see if it works when it's removed. Nz should return whatever you tell it to IF the value passed is Null. It's not like we're trying to set the value of a number field to a string, we're passing a value (or Null) to a function to see what it returns. If it's a number, that ought to be a number . If Null, it should be whatever you tell it to be.

EDIT -don't post more databases. I'm not about to start over with a new attachment. Hang tight - these things take a moment or two.
 

Micron

AWF VIP
Local time
Today, 04:53
Joined
Oct 20, 2018
Messages
3,206
OK, what I wrote DOES work if there are no defaults.
Code:
    If Not Nz(Me.cbopsdCode, "") = "" And Nz(Me.numberOfpsd, "") = "" Then
        MsgBox "Please enter the number of products!", vbInformation, "Atention!"
        Cancel = True
        Exit Sub
    End If
psdCode.jpg
Or did I do something wrong?
P.S. Bob, you are too kind. Hate to disappoint you, but I figured the main form was the wrong place. I guess I forgot that the main form can know when a sub-sub form is Dirty. Perhaps it is the linked child/master fields, but I didn't check to see what they are here.
 

tihmir

Registered User.
Local time
Today, 01:53
Joined
May 1, 2018
Messages
142
Did you remove the zero default value?
Here is my big mistake. I didn't realize I had to remove Default value from the table! I am I am sorry about that!
Now the code is works perfect!
One BIG thanks to you, Micron!!! 🤗
 

Attachments

Micron

AWF VIP
Local time
Today, 04:53
Joined
Oct 20, 2018
Messages
3,206
I did mention that, but maybe you didn't see it because it was an edit instead of a new post. Sorry about that.
EDIT - first issue I see is that this will never work because you left the default value of 0 on number fields when you created the tables. So when you go to a new record, the textbox(es) will never be null. Remove that setting.
Glad you finally got it solved.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom