473,802 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nulls Escaping If Else Logic

132 New Member
The code pasted below does not quite work as intended. I have a text box (txtSearch) on a form. Once the user enters a number (SSN) it willsearch for a match. One of the tests checks for a null or blank value. If the user fails to enter a number and clicks the UPDATE button, they should get a message that reads "No SSN Entered, Please Enter SSN" Instead they get this message "Match found for " - - ". I'm pulling my hair out over this one......See anything I'm missing as to why the code does not work?? I am using Access 2002. The code in question is in BOLD

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdUpdateSSN_Click()
  2.  
  3.     Dim SSNreplace As String
  4.     Dim strSearch As String
  5.     Dim iReturn As Integer
  6.  
  7.  
  8. On Error GoTo Error_Routine
  9.  
  10. 'Check txtSearch for Null value or Nill Entry first.
  11.  
  12.    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
  13.        If blnOnButtonClicked = True Then
  14.              Me![txtSearch].SetFocus
  15.        Else
  16.               MsgBox "Please enter an SSN.", vbOKOnly, "Enter Search Criteria"
  17.               Me![txtSearch].SetFocus
  18.        End If
  19.    End If
  20.  
  21. '-------------------------------------------------------------
  22. 'Performs the search using value entered into txtSearch
  23. 'and evaluates this against values in SSN. The FindRecord
  24. ' command requires focus to be set on the control that is returning
  25. ' the match to the search string
  26.  
  27.     DoCmd.ShowAllRecords
  28.  
  29.     If Nz(Me!txtSearch, "") <> "" Then
  30.         Me.SSN.SetFocus
  31.         DoCmd.FindRecord Me!txtSearch
  32.     Else
  33.             txtSearch.SetFocus
  34.     End If
  35.     SSN.SetFocus
  36.     SSNreplace = SSN.Text
  37.     txtSearch.SetFocus
  38.     strSearch = txtSearch.Text
  39.  
  40. 'If matching record found sets focus in SSN and shows msgbox
  41. 'and clears search control
  42.  
  43.     If Val(SSNreplace) = Val(strSearch) Then
  44.         MsgBox "Match Found For: " & strSearch, , "Match Found"
  45.         SSN.SetFocus
  46.         txtSearch = ""
  47.         btnToggle_Click
  48.  
  49.     'Value not found sets focus back to txtSearch and shows msgbox   
  50.    Else
  51.       If Nz(Me!txtSearch, "") = "" Then
  52.         iReturn = MsgBox("No SSN Entered.: - Retry or Cancel? ", vbRetryCancel)
  53.       Else
  54.         iReturn = MsgBox("Match Not Found For: " & strSearch & " - Retry or Cancel? ", vbRetryCancel, "No Match Found")
  55.       End If
  56.       If iReturn = 4 Then
  57.             txtSearch.SetFocus
  58.       Else
  59.             btnToggle_Click
  60.       End If
  61.    End If
  62. Exit_Continue:
  63.     Exit Sub
  64. Error_Routine:
  65.     MsgBox "Error# " & Err.Number & " " & Err.Description
  66.     Resume Exit_Continue
  67. End Sub
  68.  
Aug 8 '07 #1
4 2089
ADezii
8,834 Recognized Expert Expert
The code pasted below does not quite work as intended. I have a text box (txtSearch) on a form. Once the user enters a number (SSN) it willsearch for a match. One of the tests checks for a null or blank value. If the user fails to enter a number and clicks the UPDATE button, they should get a message that reads "No SSN Entered, Please Enter SSN" Instead they get this message "Match found for " - - ". I'm pulling my hair out over this one......See anything I'm missing as to why the code does not work?? I am using Access 2002. The code in question is in BOLD

Private Sub CmdUpdateSSN_Cl ick()

Dim SSNreplace As String
Dim strSearch As String
Dim iReturn As Integer


On Error GoTo Error_Routine

'Check txtSearch for Null value or Nill Entry first.

If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
If blnOnButtonClic ked = True Then
Me![txtSearch].SetFocus
Else
MsgBox "Please enter an SSN.", vbOKOnly, "Enter Search Criteria"
Me![txtSearch].SetFocus
End If
End If

'-------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in SSN. The FindRecord
' command requires focus to be set on the control that is returning
' the match to the search string

DoCmd.ShowAllRe cords

If Nz(Me!txtSearch , "") <> "" Then
Me.SSN.SetFocus
DoCmd.FindRecor d Me!txtSearch
Else
txtSearch.SetFo cus
End If
SSN.SetFocus
SSNreplace = SSN.Text
txtSearch.SetFo cus
strSearch = txtSearch.Text

'If matching record found sets focus in SSN and shows msgbox
'and clears search control

If Val(SSNreplace) = Val(strSearch) Then
MsgBox "Match Found For: " & strSearch, , "Match Found"
SSN.SetFocus
txtSearch = ""
btnToggle_Click

'Value not found sets focus back to txtSearch and shows msgbox

Else
If Nz(Me!txtSearch , "") = "" Then
iReturn = MsgBox("No SSN Entered.: - Retry or Cancel? ", vbRetryCancel)
Else
iReturn = MsgBox("Match Not Found For: " & strSearch & " - Retry or Cancel? ", vbRetryCancel, "No Match Found")
End If
If iReturn = 4 Then
txtSearch.SetFo cus
Else
btnToggle_Click
End If
End If

Exit_Continue:
Exit Sub
Error_Routine:
MsgBox "Error# " & Err.Number & " " & Err.Description
Resume Exit_Continue
End Sub
It looks like a failure to Exit the Sub-Routine if the User does not enter a SSN. Try adding Line #8 to your code. Good Luck. For future reference, please use Code Tags when displaying you code, it is very difficult to read without them.
Expand|Select|Wrap|Line Numbers
  1. 'Check txtSearch for Null value or Nill Entry first.
  2. If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
  3.   If blnOnButtonClicked = True Then
  4.     Me![txtSearch].SetFocus
  5.   Else
  6.     MsgBox "Please enter an SSN.", vbOKOnly, "Enter Search Criteria"
  7.     Me![txtSearch].SetFocus
  8.       Exit Sub
  9.   End If
  10. End If
Aug 8 '07 #2
Proaccesspro
132 New Member
It looks like a failure to Exit the Sub-Routine if the User does not enter a SSN. Try adding Line #8 to your code. Good Luck. For future reference, please use Code Tags when displaying you code, it is very difficult to read without them.
Expand|Select|Wrap|Line Numbers
  1. 'Check txtSearch for Null value or Nill Entry first.
  2. If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
  3.   If blnOnButtonClicked = True Then
  4.     Me![txtSearch].SetFocus
  5.   Else
  6.     MsgBox "Please enter an SSN.", vbOKOnly, "Enter Search Criteria"
  7.     Me![txtSearch].SetFocus
  8.       Exit Sub
  9.   End If
  10. End If
No difference.....

How does one use code tags??
Aug 9 '07 #3
missinglinq
3,532 Recognized Expert Specialist
I can't show you, because placing the tags here would format the text as code, and you wouldn't see them!

Select/hi-lite the code in your post.
Click on the # icon at the top of the editing box.
You'll see

{code}
Your code here
{/code}

except the brackets will actually be square brackets [ ]. For VBA code you need to then change the the {code} to {code=vb} one word with no space between code and =vb.

Linq ;0)>
Aug 9 '07 #4
JKing
1,206 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1.         If Val(SSNreplace) = Val(strSearch) Then 
  2.         MsgBox "Match Found For: " & strSearch, , "Match Found"
  3.         SSN.SetFocus
  4.         txtSearch = ""
  5.         btnToggle_Click
  6.  
The bolded line will still be true if both strings = ""

I think you need to rethink your if else logic to properly trap this.
Aug 9 '07 #5

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

Similar topics

14
4118
by: Ian Rastall | last post by:
Sorry for the double question. I'm having a terrible time figuring out how to escape apostrophes in my mySQL database. Perhaps they have to be escaped in the PHP, using mysql_real_escape_string? This is the code: http://www.gongfamily.net/code.txt The page in question is:
3
2014
by: aaj | last post by:
Hi I am probably going to regret asking this because I'm sure you are going to tell me my design is bad 8-) ah well we all have to learn.... anyway I often use Nulls as a marker to see if certain tasks have been completed. A typical example would be a column say invoice_value
7
1195
by: grist2mill | last post by:
I have a simple table, for some reason, certain columns seem to accept Nulls even though they shouldn't, for example the I can set the 'Name' field to Null using my web application or directly in Enterprise Manager. field How do I prevent this? However the 'RecCreated' doess not permit nulls. CREATE TABLE . ( IDENTITY (1000, 1) NOT NULL , (50) NOT NULL ,
4
10637
by: sankofa | last post by:
hi, i can't seem to be able to escape my single quote properly... is it even possible in javascript? this is a portion of my code.. var DLEWIS="Pastor Lewis"; .... Sermon is a yser-defined class .. var en_20031102=new Sermon("11/02",DLEWIS,"The Lord\'s Supper: The Art Of
1
2073
by: PST | last post by:
Here's a problem I'm trying to deal with: I'm working on a Frontpage 2000 website for a boat handicapping system, built in Access 97. What I'm trying to accomplish is: The user enters a boat name in a text field OR a sail number in a text field, and gets the desired boat record back (an exact match).
4
1773
by: Marcus | last post by:
Wondering if it's possible to allow for Null enteries in SQL/VB code. The example below doesn't work. Am I missing something? Or, is this just not possible? strSQL = "SELECT * FROM tblData " & _ "WHERE " & "tblData.Date = #" & !! & " Or (" & !! Is Null & ")# AND (" & strCriteria & ");"
2
15902
by: Rey | last post by:
Howdy all. My problem deals w/inserting nulls into database (SQL Svr 2K) for the datetime fields activityDate and followUpDate where nulls are allowed. >From the web form, the user can type in/select the activity or followup date. If, for this exercise, the followupdate textfield is empty, then when the insert method of the class calls the InsertActivityLog stored procedure, how can I get nulls inserted instead of 1/1/1900 because of
24
1373
by: Karen Hill | last post by:
Suppose you have a textBox control. It is empty and you send the this.textBox1.Text.ToString() value into a database. The control does not send a NULL but instead a "". What is the _CORRECT_ way (e.g. the way the C# language designers at MS would do it) to handle this situation. I know you could just test for a "" and then have code that would insert a NULL value like this: if (this.textBox1.Text.ToString() == '') {
5
1715
by: Nick | last post by:
Hey there, I'm trying to get a textbox (using ASP.NET / VB.NET) to display XML without freaking out the browser afterwards. Currently I have the textbox displaying the XML fine, but that's when things go funny, the second another postback occurs it complains. I thought that a textbox would have it's contents escaped in on way or another, obviously not, any idea how I can get the page to ignore it's contents? I don't want it to use...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.