473,396 Members | 2,081 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,396 software developers and data experts.

Nulls Escaping If Else Logic

132 100+
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 2074
ADezii
8,834 Expert 8TB
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_Click()

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 blnOnButtonClicked = 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.ShowAllRecords

If Nz(Me!txtSearch, "") <> "" Then
Me.SSN.SetFocus
DoCmd.FindRecord Me!txtSearch
Else
txtSearch.SetFocus
End If
SSN.SetFocus
SSNreplace = SSN.Text
txtSearch.SetFocus
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.SetFocus
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 100+
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 Expert 2GB
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 Expert 1GB
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
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? ...
3
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...
7
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...
4
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...
1
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...
4
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 " &...
2
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...
24
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_...
5
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...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.