472,808 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Runtime error 2137: You can't use find or replace now.

I have created a form to allow users to add a new record and/or search for an existing record based on SSN. If the SSN the user enters into SrchID_text is found, the form is populated and a message appears telling the user that the record exists and they can edit existing information or add new information. If the SSN is not found, a new record is supposed to be created and a message appears telling the user that no match was found and they can begin entering data.

My problem occurs when there are no records in the database.

How do I get around this?

Please see code below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub SrchID_But_Click()
  3.     Dim strStudentRef As String
  4.     Dim strSearch As String
  5.  
  6. 'Check SrchID_text for Null value or Nill Entry first.
  7.  
  8.     If IsNull(Me![SrchID_Text]) Or (Me![SrchID_Text]) = "" Then
  9.         MsgBox "Please enter a SSN to search for!", vbOKOnly, "Invalid Search Criterion!"
  10.          Me!SrchID_Text.SetFocus
  11.     Exit Sub
  12. End If
  13. '---------------------------------------------------------------
  14.  
  15. 'Performs the search using value entered into SrchID_text
  16. 'and evaluates this against values in SSN
  17.  
  18.     DoCmd.ShowAllRecords
  19.     DoCmd.GoToControl ("SSN")
  20.     DoCmd.FindRecord Me![SrchID_Text]
  21.  
  22.     SSN.SetFocus
  23.     strStudentRef = SSN.Text
  24.     SrchID_Text.SetFocus
  25.     strSearch = SrchID_Text.Text
  26.  
  27. 'If matching record found fills in data and
  28. 'sets focus on participant's first name and
  29. 'clears search control
  30.  
  31.     If strStudentRef = strSearch Then
  32.         MsgBox "Match Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please edit or add data as needed.", , "Existing Record Found"
  33.         F_Name.SetFocus
  34.         SrchID_Text = ""
  35.  
  36.     'If value not found sets SSN equal to searched SSN and
  37.     'informs user to begin entering data and sets focus on
  38.     'F_Name
  39.  
  40.     Else
  41.            MsgBox "Match Not Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please begin entering data for this new participant.", _
  42.             , "New Participant!"
  43.             DoCmd.GoToRecord , , acNewRec
  44.             SSN.SetFocus
  45.             SSN.Text = strSearch
  46.             LWIA_Combo.SetFocus
  47.  
  48.     End If
  49.  
  50. End Sub
  51.  
  52.  
Nov 19 '07 #1
5 9063
Rabbit
12,516 Expert Mod 8TB
Me.Recordset.RecordCount will let you know if you have at least one record.
Nov 19 '07 #2
Exactly how would I incorporate this into my code so that when a user enters the very first record, it will add a new record using the SSN entered?
Nov 20 '07 #3
Rabbit
12,516 Expert Mod 8TB
You mean like a If Me.Recordset.RecordCount = 0 Then ...?
From your code you seem to know how to use an If/Then statement.
Nov 20 '07 #4
Yes I obviously do... However, I have tried various placements of the If me.recordset.recordcount = 0 then statement and nothing works
Nov 20 '07 #5
Rabbit
12,516 Expert Mod 8TB
Yes I obviously do... However, I have tried various placements of the If me.recordset.recordcount = 0 then statement and nothing works
Show me one of your placements.
Nov 20 '07 #6

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

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
6
by: Dan Roberts | last post by:
I am running some off-the-shelf software that is written in ASP, which uses JScript to generate dynamic content within HTML forms. There are several ASP pages which are partially rendering to IE,...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
3
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
11
by: LayneMitch via WebmasterKB.com | last post by:
Hello. This is a reference file from a book I read in which the core subject is the use of 'event listeners'. I'm trying to load the file in Firefox and it's giving me an error message: ...
14
by: asmx126453 | last post by:
hey guys hope anyone knows what this error means i get the error when i push a button to add values in a SQL database the code were the error point to is this #region filling in txtfields from...
1
by: resqtech | last post by:
I am having an issue with an Access Database that worked at one time and after a Windows Update that screwed up the profile it stopped working. The following is what VB is stating causes the error. ...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.