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

Find record on form with Composite PK

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.findrecord before but I can't see how to do this with a composite PK.

Any suggestions?

Thanks
Kirsty
Nov 12 '09 #1
6 2338
ChipR
1,287 Expert 1GB
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
Excellent. I'll try that!

Thanks.
Nov 12 '09 #3
NeoPa
32,556 Expert Mod 16PB
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 Expert 8TB
@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 Expert Mod 2GB
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,556 Expert Mod 16PB
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
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...
1
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
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...
3
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...
0
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...
7
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...
1
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...
3
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...
1
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.