473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

One checkbox working one check box not -- same code

I have two checkboxes on my form. What I'm trying to do is if the checkbox is checked, a related field must have an entry. One checkbox is bringing up the msgbox, the other is not.

First code works:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CkSAOntwkPOC_AfterUpdate()
  2. If CkSAOntwkPOC = -1 And Pref_DSN = "" Then
  3. Cancel = True
  4. MsgBox "this record..."
  5. Pref_DSN.setfocus
  6. end If
  7. End Sub 
  8.  
Second Code only works if the And... is left off
Expand|Select|Wrap|Line Numbers
  1. Private Sub CkDTSPO_AfterUpdate()
  2. If CkDTSPO = -1 And PhoneListName = "" then
  3. Cancel = True
  4. MsgBox "This record requires..."
  5. PhoneListName.setfocus
  6. End If
  7. End Sub
  8.  
Like I said, if I take the -- And PhoneListName = "" off, it works.

What could be the difference?

Thx
Jason
Apr 5 '13 #1

✓ answered by Rabbit

Are you sure the PhoneListName is a blank string and not a null? A null can look like a blank string but they are not the same thing. To cover both possibilites, you should use
Expand|Select|Wrap|Line Numbers
  1. Nz(FieldName, "") = ""
Where the Nz function converts nulls to the blank string.

5 1116
Also, the second one works if I put And PhoneListName = "1" and then if there is a 1 in the field it works correctly.
So, it has something to do with the ""
Apr 5 '13 #2
Rabbit
12,516 Expert Mod 8TB
Are you sure the PhoneListName is a blank string and not a null? A null can look like a blank string but they are not the same thing. To cover both possibilites, you should use
Expand|Select|Wrap|Line Numbers
  1. Nz(FieldName, "") = ""
Where the Nz function converts nulls to the blank string.
Apr 5 '13 #3
Hmm, never seen that before. I had tried Is Null but that didn't work either. the Nz thing worked great.

thx
Apr 5 '13 #4
Rabbit
12,516 Expert Mod 8TB
Is Null is a SQL only thing. The equivalent in VBA code is the IsNull() function.
Apr 5 '13 #5
Ahh, good to know, I didn't try IsNull().
Apr 5 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Si | last post by:
Hi Guys I am using this code to execute an Access VBA function from ASP: strDbName = strDataSource & "data\webjobs.mdb" Set objAccess = Server.CreateObject("Access.Application")...
4
by: LRW | last post by:
Very basic, very simple, but I can't get a checkbox to check when the value of a text field changes to something greater than 0. Here's what I have: THE JAVASCRIPT: <script...
5
by: Terje | last post by:
Title says all, if a user check checkbox1 chechbox3 will also be checked, how do I do this? Have searched around but kan only find out how to check the same box Terje
8
by: Sandy | last post by:
Hello - This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't...
4
by: jason | last post by:
i am writing some simple web forms with VB.NET as the code-behind language. the code-behind files import a C# class library namespace from a .dll which is in the references list. however,...
2
by: rtilley | last post by:
What is the most common way to spell check comments in code? Are there any idle plugins or modules that do this? Thanks!
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
7
imrosie
by: imrosie | last post by:
Hello, I don't completely understand the working of these functions, but it's been suggested that these will give me what I need. I have a database that pulls in image files (stores the...
0
by: Nolanclark | last post by:
Hi there. I've read a previous thread regarding the Old VB 6 checkbox array and how it's not really needed any more. That's fine, but I'm not really sure how to implement the checkbox control array...
3
by: JamesB | last post by:
I am trying to insert a row to an Access database: INSERT INTO tblTest (Val1, Val2, Val3, Val4, Val5) VALUES ('blah', 0, '', '', 'foo'); If I run this in my code: String insStr = "INSERT...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.