When is a Null not a Null?

I have a form which is used for adding and entering data depending on
where it is called from. When called in add mode (acFormAdd) a blank
form is openned.

When the cursor enters the text box [Name]  on the form field I am
trying test whether it is empty so that a search form can be openned
if a new name is to be added. (I don't want the search form to open in
cases when the form already has data in and I am editing rather than
adding data). The form is based on a query and the data displayed in
[Name] is the result of a calculated field in the query which
concatenates firstname and surname from a table.

I have tried this

Private Sub Name_Enter()
    If IsNull(Me![Name]) = True Then
           code if name is blank
    End If
End Sub

and this

Private Sub Name_Enter()
    If Me![Name] = "" Then
            code if name is blank
    End If
 End Sub

to test for the text box being blank but neither works.  I can only
suppose that because the contents of text box is based on a
calculation it is not actually Null or empty when nothing is displayed
in it. Can anyone explain more about this and suggest a way in which I
can perform a test to show if it is "empty" in these circumstances?
Chris

0
chris
7/5/2007 1:28:16 PM
access.forms 6864 articles. 2 followers. Follow

8 Replies
1132 Views

Similar Articles

[PageSpeed] 33

When are you executing this?  Put in a debug stop and watch for the value of
the field.  Otherwise, try using the functions Len() and Nz().

chris wrote:
>I have a form which is used for adding and entering data depending on
>where it is called from. When called in add mode (acFormAdd) a blank
>form is openned.
>
>When the cursor enters the text box [Name]  on the form field I am
>trying test whether it is empty so that a search form can be openned
>if a new name is to be added. (I don't want the search form to open in
>cases when the form already has data in and I am editing rather than
>adding data). The form is based on a query and the data displayed in
>[Name] is the result of a calculated field in the query which
>concatenates firstname and surname from a table.
>
>I have tried this
>
>Private Sub Name_Enter()
>    If IsNull(Me![Name]) = True Then
>           code if name is blank
>    End If
>End Sub
>
>and this
>
>Private Sub Name_Enter()
>    If Me![Name] = "" Then
>            code if name is blank
>    End If
> End Sub
>
>to test for the text box being blank but neither works.  I can only
>suppose that because the contents of text box is based on a
>calculation it is not actually Null or empty when nothing is displayed
>in it. Can anyone explain more about this and suggest a way in which I
>can perform a test to show if it is "empty" in these circumstances?
>Chris

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200707/1

0
kingston
7/5/2007 1:53:06 PM
"chris" <chris.edwards@kirkhousetrust.org> wrote in message 
news:1183642096.085161.240750@r34g2000hsd.googlegroups.com...
>
> I have a form which is used for adding and entering data depending on
> where it is called from. When called in add mode (acFormAdd) a blank
> form is openned.
>
> When the cursor enters the text box [Name]  on the form field I am
> trying test whether it is empty so that a search form can be openned
> if a new name is to be added. (I don't want the search form to open in
> cases when the form already has data in and I am editing rather than
> adding data). The form is based on a query and the data displayed in
> [Name] is the result of a calculated field in the query which
> concatenates firstname and surname from a table.
>
> I have tried this
>
> Private Sub Name_Enter()
>    If IsNull(Me![Name]) = True Then
>           code if name is blank
>    End If
> End Sub
>
> and this
>
> Private Sub Name_Enter()
>    If Me![Name] = "" Then
>            code if name is blank
>    End If
> End Sub
>
> to test for the text box being blank but neither works.  I can only
> suppose that because the contents of text box is based on a
> calculation it is not actually Null or empty when nothing is displayed
> in it. Can anyone explain more about this and suggest a way in which I
> can perform a test to show if it is "empty" in these circumstances?
> Chris
>

Hi Chris.

For starters, don't use "Name" because it's a reserved word.  Second, don't 
use "!" to refer to a text box, use ".".  Third, give your controls 
meaningful prefixes - a lot of developers use "txt" for text boxes - it 
helps make your code more understandable.  So ... rename your calculated 
field FullName, your text box txtFullName and try

If Me.txtFullName = "" Then

BUT ... is your calculated field really ever empty?  Won't there be a space 
and/or comma in it?

Keith.
www.keithwilby.com 

0
Keith
7/5/2007 1:53:53 PM
Don't use Name as a name.  It is an Access reserved word.  Uninitialized 
controls are Null unless either at the table or form level you have defined a 
default value or if by change a user enteres a space in the control.  To test 
for either Null or and empty string:

    If Trim(Nz(Me.txtName,vbNullString)) = vbNullString Then

-- 
Dave Hargis, Microsoft Access MVP


"chris" wrote:

> 
> I have a form which is used for adding and entering data depending on
> where it is called from. When called in add mode (acFormAdd) a blank
> form is openned.
> 
> When the cursor enters the text box [Name]  on the form field I am
> trying test whether it is empty so that a search form can be openned
> if a new name is to be added. (I don't want the search form to open in
> cases when the form already has data in and I am editing rather than
> adding data). The form is based on a query and the data displayed in
> [Name] is the result of a calculated field in the query which
> concatenates firstname and surname from a table.
> 
> I have tried this
> 
> Private Sub Name_Enter()
>     If IsNull(Me![Name]) = True Then
>            code if name is blank
>     End If
> End Sub
> 
> and this
> 
> Private Sub Name_Enter()
>     If Me![Name] = "" Then
>             code if name is blank
>     End If
>  End Sub
> 
> to test for the text box being blank but neither works.  I can only
> suppose that because the contents of text box is based on a
> calculation it is not actually Null or empty when nothing is displayed
> in it. Can anyone explain more about this and suggest a way in which I
> can perform a test to show if it is "empty" in these circumstances?
> Chris
> 
> 
0
Utf
7/5/2007 2:16:02 PM
<picky>
There's nothing wrong with using ! rather than . when referring to a 
control.

In fact, technically it's the correct syntax (while . isn't).
</picky>

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Keith Wilby" <here@there.com> wrote in message 
news:468cf478$1_1@glkas0286.greenlnk.net...

> Second, don't use "!" to refer to a text box, use ".". 


0
Douglas
7/5/2007 2:22:14 PM
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
news:%23dQSj$wvHHA.736@TK2MSFTNGP06.phx.gbl...
> <picky>
> There's nothing wrong with using ! rather than . when referring to a 
> control.
>
> In fact, technically it's the correct syntax (while . isn't).
> </picky>
>

You surprise me Doug.  Not only do you lose Intellsense with Bang, you also 
lose compiling's ability to identify missing controls.  It's Dot for me 
every time :-)

Keith. 

0
Keith
7/5/2007 3:11:12 PM
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
news:%23dQSj$wvHHA.736@TK2MSFTNGP06.phx.gbl...
> <picky>
> There's nothing wrong with using ! rather than . when referring to a 
> control.
>
> In fact, technically it's the correct syntax (while . isn't).
> </picky>
>

OK, having just read this

http://www.dbforums.com/archive/index.php/t-1259776.html

I concede that Bang is considered to be correct.  However, since I prefer 
the Dot method and haven't suffered any ill-effects (yet) I'll continue so 
to do :-)

Regards,
Keith. 

0
Keith
7/5/2007 3:21:02 PM
"Keith Wilby" <here@there.com> wrote in message 
news:468d0697$1_1@glkas0286.greenlnk.net...
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
> news:%23dQSj$wvHHA.736@TK2MSFTNGP06.phx.gbl...
>> <picky>
>> There's nothing wrong with using ! rather than . when referring to a 
>> control.
>>
>> In fact, technically it's the correct syntax (while . isn't).
>> </picky>
>>
>
> You surprise me Doug.  Not only do you lose Intellsense with Bang, you 
> also lose compiling's ability to identify missing controls.  It's Dot for 
> me every time :-)

I didn't say I don't use .

I was simply commenting that there's nothing wrong with using !.  <g>

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



0
Douglas
7/5/2007 3:22:33 PM
Thanks for the advice on my particular problem and for the exchanges
on bang vs dot. I had never really understood the reasons for use of !
when it seemed that dot would do anyway and seems to work in all
circumstances.
Chris

0
chris
7/9/2007 1:32:59 PM
Reply:

Similar Artilces:

if A1=Null and B1=A1 why is result in B1=0 ??
if A1=Null and B1=A1 why is result in B1=0 ?? because of this I get wrong result for average calculations: average for (6,8,0) <> average for (6,8,null) Use =IF(A1="","",A1) -- HTH RP (remove nothere from the email address if mailing direct) "WGeorg" <WGeorg@discussions.microsoft.com> wrote in message news:09FCCF25-D0DC-4B1E-BFA1-CEF9A9327C46@microsoft.com... > if A1=Null and B1=A1 why is result in B1=0 ?? > because of this I get wrong result for average calculations: average for > (6,8,0) <> average for (6,8,null) Use this ...

Null Is Null
I've got a text box in a report that's not returning properly. Here's its Control Source: =[Reports]![rptFGPackConfigsPKWeights]![srptFGPKConfigsSUPK_totalwt]! [SumWtg]+IIf(IsNull([Reports]![rptFGPackConfigsPKWeights]! [srptFGPKConfigsTPK_totalwt]![SumWtg]),Null,"") This returns #Error. It's definitely my IIf statement as it returns properly when removed however there are times when [srptFGPKConfigsTPK_totalwt].[SumWtg] will be null. In fact, this subreport will not appear if no records exist. I suspect that this is the problem. How can I write this Control Source t...

Syntax for Is Not Null ?
When one of our forms is opened (Current event) I want a message box fired by certain conditions (that the Ref control does have a value, but the Country control is empty). I have tried various bits of code along the lines shown below, but keep getting runtime errors. Wot's wrong with the following, please? If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter the country!" Many thanks CW CW - Try this: If (not isnull([Me.Ref])) AND IsNull([Me.Country]) Then MsgBox "Please enter the country!" -- Daryl S ...

When is a Null not a Null?
I have a form which is used for adding and entering data depending on where it is called from. When called in add mode (acFormAdd) a blank form is openned. When the cursor enters the text box [Name] on the form field I am trying test whether it is empty so that a search form can be openned if a new name is to be added. (I don't want the search form to open in cases when the form already has data in and I am editing rather than adding data). The form is based on a query and the data displayed in [Name] is the result of a calculated field in the query which concatenates firstname and surn...

What is the Null character?
What is the character sequence that Excel uses to represent an empty cell? I am using a formula and when it returns false, I would like for it to represent the cell as if it was empty. I have tried using "" as an empty cell, but excel recognizes that this is a value, not an empty cell. You can't do what you want to do. A formula always returns *something*. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Quinn Ramsey" <Quinn Ramsey@discussions.microsoft.com> wrote in message news:D67F6311-0CCA-48B5-A...

Charting null values
I have a chart that is plotting null values. I tried the formula =if(C25="",N/A(),Sum(C22:C25)). I've also deleted the formula to create a completely null cell. I've been to Tools, Options, Chart and selected Plot empty cells as Not plotted, zero and Interpollated As well as turning Plot Visible Cells only (turned it on and off) Nothing seems to make a difference. Any suggestions? Stephanie, what kind of chart are you using? Can you give an example of how your data table looks like? br, Henk "StephanieH" wrote: > I have a chart that is plotting ...

NULL values
Working with a downloaded table form a Lotus Notes contact manager. Now in access call tblclients. I query certain info. to update the records. BUT...'Is Null' does not work. It comes back empty and there are definitely empty contents in the fields I chose. I know how to do this as it works in my other tables on other databases. The only difference I can see in this table as opposed to tables created directly in Access is the Field Design property called Unicode Compression saying No instead of the default Yes. I changed the Unicode to Yes in case this had something to do with it and ...

PrimaryContactID NULL
Hello, i have discovered a strange behavior of CRM regarding the relationship between accounts and contacts: Some of my accounts show up a referenced contact but do not have a PrimaryContactID GUID in the databasefield. Both where converted from a lead which is refrenced with the correct GUID in the OriginatingLeadID Field in the database? Any idea how this can happen? Regards Sebastian When you convert a lead into an account/contact the contact references the account throught the parent customer field. The account does not reference the contact (this would be the primary contact fi...

Using CORREL with arrays containing null values
XL Gurus... I'm using the CORREL function, but one of the arrays I'm comparing has null values (entered as #N/A), so my result is #N/A. How can I modify my formula to correlate all the points in the 2 arrays, apart from the null values and their corresponding entries in the other array? You might incorporate an IF function, along the lines of IF(ISNUMBER(your array function here),your array function here,0) It seems redundant, but it evaluates the array function to determine if it is numeric. ...

Hide Sub Report(s) when records are null
I am running Access 2007 sp2 MSO. I have a report that has three (3) sub reports. There are times when not all three sub reports have values to display. Is there a way to code the given report to not be visible if there are no records to report? The second part of this question would be if there is a way to make the report invisible is it also possible to code so that the space where the report would normally reside would not be taken with a blank space (the foot print of where the report normally resides)? -- Bruce ...

Nulls in SP
I have a stored procedure (see below) that I need to make the last 2 parameters optional and place a NULL value when they are not sent. Can someone help show me how this is done? Thanks. David ALTER PROCEDURE [dbo].[mc_insHistoryDates] @PeopleLinkID int, @HistoryTypeID int, @HistoryReasonID int, @HistoryDate date, @HistoryDateTo date, @HistoryText varchar(1000) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; INSERT INTO [MCFICore].[dbo].[HistoryDates] ([PeopleLinkID] ...

Unique unless null?
Is there a way to set up a constraint, or something with the effect of a constraint, to prevent two rows in a table from having the same non-null value in a particular column while allowing multiple rows to have NULL in that row? Consider a table, some of whose data is imported from an external source, and the table has a column for storing the primary key value associated with the imported data in its source database. In other words, one way of looking at this column is that it's a 1..(0, 1) foreign key into another table that isn't present. Hi Harlan What version a...

Is null
Hi I'm having a problem with the "Is null" criteria in one of my queries. My query shows that there are 420 records with "is null" in the copies column. However in the corresponding table there are 467 records that have a blank entry in the copies column. Where am I going wrong? Thanks again! Adam Are you sure they're all Null? Some of the records could contain an empty field (""), or a space character (" "). http://www.databasedev.co.uk/null_values_defined.html "Adam" wrote: > Hi > > I'm having a problem with th...

how do i use an if is null, and if is not null statement together
I have to compare two columns of data, and show the status in column three. Column1 = enrolleddate, Column 2= DisenrolledDate, Column 3 = Status If column1 and column2 are null, "Active", if column2 is not null, then disenrolleddate Thanks for helping me. If you were using a spreadsheet, you might need that third column. In Access you can simply use a query to do the comparison and generate the "calculated" value. Regards Jeff Boyce Microsoft Office/Access MVP "latha" <latha@discussions.microsoft.com> wrote in message news:A4366DA3-9E0E-48C8-BB30-452...

OnCtlColorDlg & return NULL
The MS documentation about WM_CTLCOLORDLG says: "If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the dialog box." The documentation about "CWnd::OnCtlColor" says something quite similar. But then when the wizzard generates OnCtlColor the included comment says: "TODO: Return a different brush if the default is not desired". Now I wonder if really a brush MUST(!) be returned. Returning NULL works. Nevertheless, that doesn't mean it's valid to do so. Finally, if I can re...

NULL DATE
This works fine if there is a date in the textbox, but if the textbox is empty or null, I get an error. This is part of an SQL statement. What can I do if it's Null so that it still works. Thanks DS Format(Forms!frmBSDiscountNames![TxtExpDate], "\#mm\/dd\/yyyy\#") Change you line to Nz(Format(Forms!frmBSDiscountNames![TxtExpDate], "\#mm\/dd\/yyyy\#")) This will return a zero legnth string instead of a null value, and will allow your code to process it. Note that if at any point you are comparing that field to Null, it will fail, and you will have to compar...

Checking a forms fields for null
Hi All, I can think of a few ways to accomplish this, but would like to know of a better way. just like when you fill out forms on the web if the field is mandatory it pops up a msg say somthing like "This field isn't optional" if it is left blank. What is the best way to do this in access on a form? I'm using now: if ISNull(myFeild1) then msgbox"Please fill in myFeild1" end if If ISNull(myFeild2) then msgbox"Please fill in myFeild2" end if if ISNull(myFeild3) then msgbox"Please fill in myFeild3" end if I use s...

httpCookie is null
I have some code that when published to an IIS 6 box it works, but IIS 7 it does not. It has to do with cookies. Have some code in a SessionModule that when the client comes to the site, a cookie is created for the duration of their session. The code looks something like this Dim ctx As HttpContext = HttpContext.Current Dim cookie As HttpCookie = ctx.Request.Cookies("TestIt") If cookie Is Nothing Then Dim newGuid As String = Guid.NewGuid().ToString Dim mTimeTick As String = System.DateTime.Now.Ticks Dim mSmashIt A...

Inserting NULL into CString
Hello all, I need to provide parameters to stored procedures, and I've been using a 'lstrcpy' to do this; but along comes a stored procedure that needs NULLS as part of the prameter string. How do I get NULLs into a string? //old stored procedure string CString str = "123456"; //new stored procedure string CString str = "123456,\0,\0,\0"; lstrcpy( (char *) pSqlStmt, "{CALL info_sp("+str+")}"); retcode = SQLExecDirect(hstmt, pSqlStmt, lstrlen((char *) pSqlStmt)); When I look at 'pSqlStmt' for the strin...

Summing with nulls
My statement select sum(column) from ( select column from table union select column2 from table2) as T Now the second part of the union returns a null. How do i sum with a null i have tried using case when then end but this does not work. The sum does return a value but it is incorrect. When the second part of the union statement is null i want to get the sum of the first part. Thanks try it with "isnull" select sum(isnull(column,0)) from yourtable "Cdudej" <jedfletcher1@gmail.com> wrote in message news:5df50a11-89a7-42d6-b92b-e611910394e6@k19g200...

CString m_pchData is null
I have a class that is derived from CCmdTarget. I have a bunch of CString class members. In the class constructor I am assigning values to them. There is one member that has m_pchData = null at the time of assignment. This is causing the program to crash. Anybody have any ideas as to why this one member is exhibiting this behavior? This looks suspiciously like you are managing to overwrite some part of the heap. I'd suggest the following approach: At the earliest possible point in the constructor, set a breakpoint. Examine the member variables. If the pointer is NULL at that p...

field Null but not Null
Don't really know how to explain this, but here goes. Have a table with fields [BLOCK], [NUMBER], and [ALPHA]. [ALPHA] can be null. These are concantenated together to form Acct# (block & "-" & number & alpha). Example, 9-152 is different account from 9-152G. I append block billing charges to a temp table for review, and then post (append) those charges to transaction table. But, here is strange thing. When I run a totals query, sometimes there are two records instead of one. For example; acct# 9-152 might show as: Acct SumOfTransactions 9-152 ...

Only Null
I need to limit this output to only records without a close date (TR_CLOSEDATE) Any suggestions??? SELECT tblTrackingData.TR_GRIEVANCECOORDINATOR, tblTrackingData.ICNNO, tblTrackingData.TR_GBU, tblTrackingData.TR_DATE_TIMERCVD_HOI, DateDiff("d",[TR_Date_TIMERCVD_HOI],Date()) AS Days, tblTrackingData.TR_CLOSEDATE FROM tblTrackingData WHERE (((tblTrackingData.TR_DATE_TIMERCVD_HOI) Between [forms]![frmreports].[txtstartdate] And [forms]![frmreports].[txtenddate])); Thank you "Ofer Cohen" wrote: > Under the TR_CLOSEDATE field write the criteria > > Is Null >...

Null
I have a database that list clients...I want to create a report that is only open clients and excludes closed clients. I created a query on which to base the report but I cannot seem to eliminate the clients that have been closed. Any suggestions? Pamelia wrote: >I have a database that list clients...I want to create a report that is only >open clients and excludes closed clients. I created a query on which to base >the report but I cannot seem to eliminate the clients that have been closed. Post back with a Copy/Paste of your query's SQL view along with an explanation...

Null value syntax of export XML
Dear all, I use excel 2003 to export a excel file into xml file. For those blank cells in the excel file, I input a ' so that excel can recognize it as a null value when exporting to xml. After exporting, the syntax of null value in the xml file will look liked <remark/> However, I expect the syntax of null value will look liked <remark></remark> Everytime I will use Notepad to modify the syntax. May I ask whether there is any method to modify the xml output syntax? Thanks. Regards, Michael ...