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
6 2344 ChipR 1,287
Recognized Expert Top Contributor
I use something like: - Dim rs As Object 'rs short for recordset
-
Dim strWhere As String
-
-
Set rs = Me.RecordsetClone
-
-
strWhere = "[field1] = " & value1 & " AND [field2] = " & value2
-
-
rs.FindFirst strWhere
-
-
If Not rs.nomatch Then
-
Me.Bookmark = rs.Bookmark
-
End If
-
-
set rs = Nothing
Excellent. I'll try that!
Thanks.
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?
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)! - Dim rs As DAO.Recordset
-
Dim strWhere As String
-
Dim varBookmark As Variant
-
-
varBookmark = Me.Bookmark
-
-
Set rs = Me.Recordset
-
-
strWhere = "[LastName] = 'NeoPa'"
-
-
rs.FindFirst strWhere
-
-
If Not rs.NoMatch Then
-
'No action needed, the Current Record in the Recordset
-
'will now become the Form's Current Record
-
Else
-
'Even though the Criteria is not met, the First Record now
-
'becomes the Current Record, so the Original Bookmark must be
-
'restored
-
MsgBox "The Criteria of " & strWhere & " could not be found"
-
Me.Bookmark = varBookmark
-
End If
-
-
Set rs = Nothing
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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?
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |