473,700 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding a Specific Record Programmaticall y

ADezii
8,834 Recognized Expert Expert
  1. Use the FindRecord Method of the DoCmd Object (least efficient) - The simplest approach for finding a specific Record is to create an Event Procedure for the Combo Box that mirrors each step of the generic Find process.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Application.Echo False
    3.  
    4.   Me![EmployeeID].SetFocus
    5.  
    6.   DoCmd.FindRecord cboFind
    7.  
    8.   cboFind.SetFocus
    9.  
    10.   Application.Echo True 
    11. End Sub
    12.  
  2. Using the ApplyFilter Method of the DoCmd Object (more efficient) - A more efficient approach is to use a Filter to select a Record directly from the Form's Recordset. The Applyfilter method lets you apply a Filter to a Table, Form, or Report to restrict or sort the Records in the Table or in the underlying Recordset of the Form or Report. You can specify a saved Query as the Filter using the filtername Argument, or you can enter a SQL Where Clause in the wherecondition Argument.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Dim strSQL As String
    3.  
    4.   strSQL = "[EmployeeID] = " & Me![cboFind]
    5.  
    6.   DoCmd.ApplyFilter wherecondition:= strSQL
    7. End Sub
  3. Using the RecordsetClone (most efficient) - This approach is the most efficient and uses the Form's RecordsetClone to refer to the Form's Recordset.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Dim strCriteria As String
    3.  
    4.   Dim rst As DAO.Recordset
    5.  
    6.   Set rst = Me.RecordsetClone
    7.  
    8.  
    9.  
    10.   strCriteria  = "[EmployeeID] = " & Me![cboFind]
    11.  
    12.   rst.FindFirst strCriteria
    13.  
    14.   Me.Bookmark = rst.Bookmark
    15. End Sub
Jun 24 '07 #1
7 79810
dima69
181 Recognized Expert New Member
  1. Use the FindRecord Method of the DoCmd Object (least efficient) - The simplest approach for finding a specific Record is to create an Event Procedure for the Combo Box that mirrors each step of the generic Find process.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Application.Echo False
    3.  
    4.   Me![EmployeeID].SetFocus
    5.  
    6.   DoCmd.FindRecord cboFind
    7.  
    8.   cboFind.SetFocus
    9.  
    10.   Application.Echo True 
    11. End Sub
    12.  
  2. Using the ApplyFilter Method of the DoCmd Object (more efficient) - A more efficient approach is to use a Filter to select a Record directly from the Form's Recordset. The Applyfilter method lets you apply a Filter to a Table, Form, or Report to restrict or sort the Records in the Table or in the underlying Recordset of the Form or Report. You can specify a saved Query as the Filter using the filtername Argument, or you can enter a SQL Where Clause in the wherecondition Argument.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Dim strSQL As String
    3.  
    4.   strSQL = "[EmployeeID] = " & Me![cboFind]
    5.  
    6.   DoCmd.ApplyFilter wherecondition:= strSQL
    7. End Sub
  3. Using the RecordsetClone (most efficient) - This approach is the most efficient and uses the Form's RecordsetClone to refer to the Form's Recordset.

    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboFind_AfterUpdate()
    2.   Dim strCriteria As String
    3.  
    4.   Dim rst As DAO.Recordset
    5.  
    6.   Set rst = Me.RecordsetClone
    7.  
    8.  
    9.  
    10.   strCriteria  = "[EmployeeID] = " & Me![cboFind]
    11.  
    12.   rst.FindFirst strCriteria
    13.  
    14.   Me.Bookmark = rst.Bookmark
    15. End Sub
A little comment to the last method.
Setting the bookmark
Expand|Select|Wrap|Line Numbers
  1. Me.Bookmark = rst.Bookmark
when the form record is already the one we are looking for may cause Access to crash.
So I would add the check like
Expand|Select|Wrap|Line Numbers
  1. If Me![EmployeeID] <> Me![cboFind] Then ...
Jul 26 '07 #2
ADezii
8,834 Recognized Expert Expert
A little comment to the last method.
Setting the bookmark
Expand|Select|Wrap|Line Numbers
  1. Me.Bookmark = rst.Bookmark
when the form record is already the one we are looking for may cause Access to crash.
So I would add the check like
Expand|Select|Wrap|Line Numbers
  1. If Me![EmployeeID] <> Me![cboFind] Then ...
Excellant point dima69 - I was totally unaware of this, but will definately keep it in mind now! Thanks.
Jul 26 '07 #3
rk2008
3 New Member
Hi,
I was looking at your 3rd example and it is similar to what I'm using for my forms. But I have a problem, If one person opens form A and select one of the record from the list it works fine. Now at the same time if second person open the same form A from the same copy of MSAccess the first form A starts pointing at the new record also and save changes to the newly selected record. How can I prevent this happen, so that each instance of form A points to its selected record?

Thanks
Mar 26 '08 #4
rk2008
3 New Member
Excellant point dima69 - I was totally unaware of this, but will definately keep it in mind now! Thanks.
Hi,
I was looking at your 3rd example and it is similar to what I'm using for my forms. But I have a problem, If one person opens form A and select one of the record from the list it works fine. Now at the same time if second person open the same form A from the same copy of MSAccess the first form A starts pointing at the new record also and save changes to the newly selected record. How can I prevent this happen, so that each instance of form A points to its selected record?
I'm using MSSQL ODBC linked tables inside MS Access.

Thanks
Mar 26 '08 #5
ADezii
8,834 Recognized Expert Expert
Hi,
I was looking at your 3rd example and it is similar to what I'm using for my forms. But I have a problem, If one person opens form A and select one of the record from the list it works fine. Now at the same time if second person open the same form A from the same copy of MSAccess the first form A starts pointing at the new record also and save changes to the newly selected record. How can I prevent this happen, so that each instance of form A points to its selected record?
I'm using MSSQL ODBC linked tables inside MS Access.

Thanks
I imagine that a Client/File Server architecture with multiple Front End Databases linked to a single Back End would solve this problem. Each Front End would now have its own, independent Form A instances, and this type of conflict should not then be a problem.
Mar 26 '08 #6
truthlover
107 New Member
This looks like something I've been trying to do, but I dont know how to implement it to try it out.

I'm already using the first example, but what I want is a pull down list to select a record. I have that working in a different form, and it's working perfectly, but I cant get it to work on the primary form.

Is it because I'm trying to pull up the record by it's Primary Key, that I've been unsucessful?

Will that third example solve that? If so, how do I implement it? If not, is there a way to do this?

BTW there was an explaination that I tried to use, but it didnt work (I posted to the thread 3/28 or 3/29.

Thanks!!!
Mar 31 '08 #7
Moussiel
1 New Member
Hello. The First solution works for me very well. Thanks for sharing and saving me from long nightmares!!! Great!!!!!
Jun 14 '16 #8

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

Similar topics

1
3277
by: Ian | last post by:
I want to open a form at a particular record, but I think I'm running into problems because the recordsource query is executing asynchronously. In the form's open event I use recordsetclone.findfirst to get a bookmark and then set the form's bookmark to this value. normally that works fine, but the form I am using has a very large number of records and isn't being set to the correct record, even though it is found successfully in the...
3
2471
by: bjaj | last post by:
Hi I got a form where I type a number. After taht I split it in two. Then I search in a table if there are any record that match the two numbers and not yet been completed. The code: VareVar = Left(Me!VareNr, 8) MyLen = Len(Me!VareNr) - 8
3
4752
by: DavidB | last post by:
New to .net....sorry if this seems repetitive I have a dataset ordered by date (SQLDataAdapter SelectCommand uses Order By) and want to find a record by a UniqueID(Identity Column). Then I want to change the position (BindingContext) in the dataset to have all my bound controls reflect the data in the found record - and the related records/tables. Problem is, it appears it can't be done.... The Dataset has to be ordered by the date...
2
11275
by: nkoske | last post by:
I have a form with a subform in datasheet view and I have a event on one of the fields in the subform, so that the user can double click it and go to expanded information based on that field. I'm using this code: Private Sub SpecimenNum_DblClick(Cancel As Integer) DoCmd.OpenForm "RDDevice", , , " = '" & Me! & "'" End Sub
2
3335
by: Timbo | last post by:
Hi there, I’m not used to working in VB and I think this situation calls for excactly that. I use Access 97 SR-2. My first table is a table containing all the Tickets I got. The field ”Ticket” is simply a ticket-number. I’ve made a form in which I am to choose an existing Ticket and write a description for it pluss other things. The description to these Tickets are stored in another table called ”LogBook”. I then made a query on all of...
4
2915
by: BerkshireGuy | last post by:
Is there a way to create a shortcut to open a MS Acccess DB and have it go to a specific record? In my DB, when a user delegates a record to another users, I currently send out an email to the personing saying they been delegated to followup on an item. I list the reference number, but was thinking that it would be really cool if I could attach a shortcut in the email that would go to the record.
3
27296
by: cmp80 | last post by:
I have a database that I am using to store student data. There are two tables and two forms to display the data: Tables tbStudent tbRE Forms fmStudent fmRE
1
6574
by: cvillav | last post by:
Hello, I am new to Access and this forums, I have two tables and two forms to display the data. Tables Tbuilding Tcriteria Forms fmbuilding
8
8229
by: Redbeard | last post by:
I have a button on a popup form that when clicked runs a code to duplicate the current record that I am viewing on my main form. It first asks me to enter a new number (primary key) into a pop-up box and then duplicates the record replacing the primary key with the new number. I use this in cases where the next record only requires a few field changes, so I don’t have to retype the hold record. The problem is that when the code runs to do...
0
8638
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
9202
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...
0
9058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8952
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
7791
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5894
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();...
0
4395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3081
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
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.