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
-
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. - '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
-
Exit Sub
-
End If
-
End If
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. - '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
-
Exit Sub
-
End If
-
End If
No difference.....
How does one use code tags??
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)> JKing 1,206
Recognized Expert Top Contributor -
If Val(SSNreplace) = Val(strSearch) Then
-
MsgBox "Match Found For: " & strSearch, , "Match Found"
-
SSN.SetFocus
-
txtSearch = ""
-
btnToggle_Click
-
The bolded line will still be true if both strings = ""
I think you need to rethink your if else logic to properly trap this.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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
|
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 ,
|
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
|
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).
| |
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 & ");"
|
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
|
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() == '')
{
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |