473,397 Members | 1,985 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,397 software developers and data experts.

rst.FindFirst - now it works, then it doesn't!

patjones
931 Expert 512MB
Hi all:

I have a form called frmChecks, with a textbox txtSearchBox. The After Update event for txtSearchBox is connected to code that searches for the inputted value in a linked table (tblEmployees):

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim strCriteria As String, errStr As String
  3.  
  4. strCriteria = "[tblEmployees].[fldEmplNum] Like '*" & Me!txtSearchBox.Value & "*'"
  5. errStr = "Employee not found..."
  6.  
  7. Set rst = Me.RecordsetClone
  8.  
  9. rst.Requery
  10.  
  11. rst.FindFirst strCriteria
  12.  
  13. If rst.NoMatch Then
  14.     MsgBox errStr, vbInformation, "Check Tracking System"
  15.     rst.MoveFirst
  16. End If
  17.  
  18. Me.Bookmark = rst.Bookmark
  19. Me!cboCheckNum = rst!fldCheckNum
  20.  
  21. rst.Close
  22. Set rst = Nothing
  23.  
This works fantastically. Then, I have another form, frmAddChecks, with a text box txtEmplERN. This textbox is connected to nearly identical code for it's After Update event:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim rst As DAO.Recordset
  3. Dim strCriteria As String
  4.  
  5. strCriteria = "[tblEmployees].[fldEmplNum] Like '*" & Me!txtEmplERN.Value & "*'"
  6.  
  7. Set rst = Me.RecordsetClone
  8.  
  9. rst.Requery
  10.  
  11. rst.FindFirst strCriteria
  12.  
  13. If rst.NoMatch Then 
  14.      'Code to raise not found error
  15. Else
  16.      'Code to do some other stuff during normal execution
  17. End If
  18.  
  19. rst.Close
  20. Set rst = Nothing
  21.  
Both forms have the exact same SQL query as a recordsource.

The problem is that the second set of code won't work! It always executes the error branch of the If statement, even though I type in values that are definitely in the table, and which are found by the first set of code. I just don't get it...

Any thoughts? Thank you.
Nov 21 '07 #1
3 2354
missinglinq
3,532 Expert 2GB
Are txtSearchBox and txtEmplERN both formatted as the same datatype?

Linq ;0)>
Nov 21 '07 #2
patjones
931 Expert 512MB
Are txtSearchBox and txtEmplERN both formatted as the same datatype?

Linq ;0)>
Hi:

Thank you for your response. The formatting on these text boxes isn't really set. It's just open format because it's always a seven-digit text string that the user enters.

The reason I left the format open rather than making it a number is because sometimes that seven digit text string starts with one or more zeroes, and if you format something like that as a number then it cuts the zeroes off.

So, being that the code is the same in both places, it's hard for me to understand why it would behave differently. I do see what you're saying though; something has to be different somewhere...
Nov 26 '07 #3
patjones
931 Expert 512MB
Hi:

Thank you for your response. The formatting on these text boxes isn't really set. It's just open format because it's always a seven-digit text string that the user enters.

The reason I left the format open rather than making it a number is because sometimes that seven digit text string starts with one or more zeroes, and if you format something like that as a number then it cuts the zeroes off.

So, being that the code is the same in both places, it's hard for me to understand why it would behave differently. I do see what you're saying though; something has to be different somewhere...
I forgot to post here and point out that I solved this problem simply by creating a new form, pasting all my controls and code over to it, and recompiling. Things worked fine. It seems like the original was somehow corrupt, if that's possible...

Anyway, thanks so much for your input!
Dec 18 '07 #4

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

Similar topics

1
by: Mike MacSween | last post by:
rstStuAddr.MoveFirst rstStuAddr.FindFirst "CountryID = 168 AND Left(CLPostCode,4) <> 'BFPO'" CountryID and CLPostCode are names of fields in rstStuAddr It works. But doesn't look like it...
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
7
by: waltvw | last post by:
I'm using FindFirst method in Access VBA to find a particular record in a recordset. I have 2 search criteria each of which works just fine if used separately as an argument in FindFirst, but NOT in...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.