UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Not Show Msgbox When Txtbos Is Null, Access 2003    
 
   
mr.siro
post Nov 8 2018, 04:05 AM
Post#1



Posts: 112
Joined: 27-January 18



hello guys, i have demo. Somebody help me, when txtbox is null i click button not show msgbox. Why is that.
This post has been edited by mr.siro: Nov 8 2018, 04:06 AM
Attached File(s)
Attached File  db38.zip ( 11.51K )Number of downloads: 5
 
Go to the top of the page
 
DanielPineault
post Nov 8 2018, 06:20 AM
Post#2


UtterAccess VIP
Posts: 6,220
Joined: 30-June 11



That's because, in your case, with your setup, it is not null but rather = "". So instead of testing for a NULL value you'd need to do something more like

CODE
    If Len(Trim(Me.Text0 & vbNullString)) = 0 Then
        MsgBox "abc"
    End If


This type of test will handle pretty much any scenario and insure an entry is there





--------------------
Daniel Pineault (2010-2018 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
mr.siro
post Nov 8 2018, 08:36 AM
Post#3



Posts: 112
Joined: 27-January 18



hello Daniel, why is "", why not is null. I hope you advice me why is that.
Go to the top of the page
 
GroverParkGeorge
post Nov 8 2018, 10:41 AM
Post#4


UA Admin
Posts: 33,958
Joined: 20-June 02
From: Newcastle, WA


PMFJI.

Null is a special concept in databases. It essentially means "not known".

It is not the sample as a Zero Length String, which is a string of 0 characters.

Open a table in datasheet view. Fields in a new record are null--there's nothing in them yet. They may or may not have a value at some point, but at the beginning, they do not. We don't know what the values will be, or even if there will be values in any field.

Now, type a value into any of those field. It's no longer null because it now has a value in it.

Now, delete what you just typed. Now the value is a Zero Length String. It is no longer null, because something was put into it, but it is now a string of 0 characters.

Here's an interesting discussion. A search here at UtterAccess and elsewhere will turn up others.

What you have to keep in mind is that we, humans, can't see the difference. However, Access DOES know the difference.
This post has been edited by GroverParkGeorge: Nov 8 2018, 10:42 AM

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
mr.siro
post Nov 8 2018, 09:25 PM
Post#5



Posts: 112
Joined: 27-January 18



hello guys, how to put that check in this function:
CODE
Private Function checkdate(ByVal txtdate As Variant) As String
If IsNull(txtdate) Then
    Exit Function
Else
    'if type txtdate value is 31/04/2018 return 30/04/2018
    If Left(txtdate, 2) > Left(DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0), 2) Then
    checkdate = DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0)
    Else
    checkdate = txtdate
    End If
End If
End Function
Go to the top of the page
 
DanielPineault
post Nov 9 2018, 08:49 AM
Post#6


UtterAccess VIP
Posts: 6,220
Joined: 30-June 11



How about

CODE
Private Function checkdate(ByVal txtdate As Variant) As String
10        On Error GoTo Error_Handler

20        If Len(Trim(txtdate & vbNullString)) = 0 Then
30            Exit Function
40        Else
               'if type txtdate value is 31/04/2018 return 30/04/2018
50            If Left(txtdate, 2) > Left(DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0), 2) Then
60                checkdate = DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0)
70            Else
80                checkdate = txtdate
90            End If
100       End If

Error_Handler_Exit:
110       On Error Resume Next
120       Exit Function

Error_Handler:
130       MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
                  "Error Number: " & Err.Number & vbCrLf & _
                  "Error Source: checkdate" & vbCrLf & _
                  "Error Description: " & Err.Description & _
                  Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
                  , vbOKOnly + vbCritical, "An Error has Occured!"
140       Resume Error_Handler_Exit
End Function






Another solution would be create a simple reusable function and call it as required, something like

CODE
Public Function HasEntry(vInput As Variant) As Boolean
10        On Error GoTo Error_Handler

20        If Len(Trim(vInput & vbNullString)) > 0 Then _
             HasEntry = True

Error_Handler_Exit:
30        On Error Resume Next
40        Exit Function

Error_Handler:
50        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
                 "Error Number: " & Err.Number & vbCrLf & _
                 "Error Source: HasEntry" & vbCrLf & _
                 "Error Description: " & Err.Description & _
                 Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
                 , vbOKOnly + vbCritical, "An Error has Occured!"
60        Resume Error_Handler_Exit
End Function


and then your code would become

CODE
Private Function checkdate(ByVal txtdate As Variant) As String
10        On Error GoTo Error_Handler

20        If HasEntry(txtdate) = True Then
30            Exit Function
40        Else
              'if type txtdate value is 31/04/2018 return 30/04/2018
50            If Left(txtdate, 2) > Left(DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0), 2) Then
60                checkdate = DateSerial(Right(txtdate, 4), Mid(txtdate, 4, 2) + 1, 0)
70            Else
80                checkdate = txtdate
90            End If
100       End If

Error_Handler_Exit:
110       On Error Resume Next
120       Exit Function

Error_Handler:
130       MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
                 "Error Number: " & Err.Number & vbCrLf & _
                 "Error Source: checkdate" & vbCrLf & _
                 "Error Description: " & Err.Description & _
                 Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
                 , vbOKOnly + vbCritical, "An Error has Occured!"
140       Resume Error_Handler_Exit
End Function





--------------------
Daniel Pineault (2010-2018 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th November 2018 - 03:33 PM