473,569 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find record on form with Composite PK

14 New Member
Hi. I am trying to move to a particular record on a form where the form has a composite PK.

The PK is made of 3 fields: ModuleID, Precedence and RecordTypeID

I have always used docmd.findrecor d before but I can't see how to do this with a composite PK.

Any suggestions?

Thanks
Kirsty
Nov 12 '09 #1
6 2344
ChipR
1,287 Recognized Expert Top Contributor
I use something like:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As Object   'rs short for recordset
  2. Dim strWhere As String
  3.  
  4. Set rs = Me.RecordsetClone
  5.  
  6. strWhere = "[field1] = " & value1 & " AND [field2] = " & value2
  7.  
  8. rs.FindFirst strWhere
  9.  
  10. If Not rs.nomatch Then
  11.     Me.Bookmark = rs.Bookmark
  12. End If
  13.  
  14. set rs = Nothing
Nov 12 '09 #2
QueenKirsty
14 New Member
Excellent. I'll try that!

Thanks.
Nov 12 '09 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Nice solution Chip.

For my curiosity, what would happen if one were to use Recordset instead of RecordsetClone? Would the Bookmark code still be required? Would there be any negative side-effects?
Nov 15 '09 #4
ADezii
8,834 Recognized Expert Expert
@NeoPa
This is my understanding of how Recordset works in this specific situation. Assuming that I am correct, its behavior is quirky to say the least. I really didn't have much time to investigate this further, so take it with a grain of salt (LOL)!
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim strWhere As String
  3. Dim varBookmark As Variant
  4.  
  5. varBookmark = Me.Bookmark
  6.  
  7. Set rs = Me.Recordset
  8.  
  9. strWhere = "[LastName] = 'NeoPa'"
  10.  
  11. rs.FindFirst strWhere
  12.  
  13. If Not rs.NoMatch Then
  14.   'No action needed, the Current Record in the Recordset
  15.   'will now become the Form's Current Record
  16. Else
  17.   'Even though the Criteria is not met, the First Record now
  18.   'becomes the Current Record, so the Original Bookmark must be
  19.   'restored
  20.     MsgBox "The Criteria of " & strWhere & " could not be found"
  21.       Me.Bookmark = varBookmark
  22. End If
  23.  
  24. Set rs = Nothing 
Nov 15 '09 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi NeoPa. There is a side-effect of using the Recordset property that I think rules it out for searching/matching applications. From the help file (with emphasis added):

"The Recordset property returns the recordset object that provides the data being browsed in a form, report, list box control, or combo box control. If a form is based on a query, for example, referring to the Recordset property is the equivalent of cloning a Recordset object by using the same query. However, unlike using the RecordsetClone property, changing which record is current in the recordset returned by the form's Recordset property also sets the current record of the form."

Using RecordsetClone, the underlying recordset has not been altered no matter what is done before or after the search. If the Recordset property was to be used, any FindFirst, MoveFirst or the like would alter the current record position in the form itself.

-Stewart
Nov 15 '09 #6
NeoPa
32,564 Recognized Expert Moderator MVP
Thanks for these chaps.

I would have thought then (from what's been posted here) that (disregarding ADezii's point about when a match is not found for a second) this would actually be quite appropriate, as that is exactly what is intended in this situation (to move the record currently being browsed on the form itself).

Having said that, we cannot disregard ADezii's point (that we ignored temporarily for clarity) totally. It seems that, after all, this is less helpful than the original technique of using the RecordsetClone property, due to the unfortunate side-effect of setting the current record to the start where no match is found.

Back to where we started with Chip's post then, but at least I (& hopefully other curious readers) have a clearer understanding of what is going on. My thanks again to all who contributed.
Nov 15 '09 #7

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

Similar topics

3
2516
by: Sarah Smith via AccessMonster.com | last post by:
I am creating a database of documents that need to be worked on, are int eh proress of being worked on, and have been completed. Sometimes the same document (an updated version) comes back for more work. I am keeping all the info in one table and using an Index numberas my Primary Key. I have a form based on this table with a Findrecord button...
1
2356
by: Apple | last post by:
May any one can teach me the easy way to create a combo box in a form to find record.
2
1274
by: kufre | last post by:
I just want to say thank you to everyone that has help me with my database. Could someone please take a look at this code and tell me what it is I'm doing wrong. I have a find command button on my form that I'm trying to use to and find a record. When I click Find on my form, I want to find the record using ProjectID and Jurisdiction. I've...
3
6211
by: Randy | last post by:
I have been able to set up a Find Record Button on my switchboard to take me to a form with the correct case number by using a parameter query and macro. When I try to run the Find Record button from the macro on the form I want to find the record in it just sits there and does not run. Could someone tell me how to fix this? Please be...
0
1529
by: AA Arens | last post by:
I made a find record button on my form "company" (with field for name, phone nr, e-mail etc.). I expect that when I focus on one of the field, the "look in" of the find-record dialog box should be set to the field, but instead of that it is set to the form name (company). To avoid it I have to set it manually to the focussed field. How to...
7
9441
by: gjoneshtfc | last post by:
Hello I want to search my database for a vehicle registration number but before i can search using the Find Record button i created i have to click in the registration field so that it is that one that is being searched. Is there any way to just click the button and by default it searches the registration field? Or... is there a way...
1
2421
by: crazdandconfusd | last post by:
I created a form based on one table and was able to find information using find record and searching entire form. Now I split the information into two tables: one for the front of a page to be printed and another for the back to be printed. Now when I search for information in the entire form and will only search the record displayed. I'm...
3
2816
by: betterdayz | last post by:
hi...im trying to design the "find record" command whereby the user enters an ID Number and than clicks ok and the database does a search for that particular ID...the wizard command uses find and replace but rather i would just like to have "find record"..ive read recent forums on the same question and decided to try a script that was posted in...
1
2566
by: farhan31 | last post by:
Hello all I have Two tables.Table 1 and table 2.Table 1 has one to many relation with Table 2.I have one main form Form1 based on table 1.On form 1 i have a sub form based on table 2.I have put a find record button on main form i.e Form 1.Master/child relation is already established.Find button works fine with main form.it changes the main form...
1
3325
Run2Eat
by: Run2Eat | last post by:
i feel like this is a doofus question... but i've created an access form and added a find record button, but when i use the form, the find record button searches the form itself, not the table. all the other buttons work, so i believe the form is linked to the table. how can i get the find record button to search the table, not the form itself?
0
7618
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...
0
7926
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. ...
0
8138
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...
1
7679
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...
0
7983
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 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...
0
6287
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...
0
5223
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...
0
3657
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...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.