473,320 Members | 2,094 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,320 software developers and data experts.

VBA code for extracting filtered record ID

I've been away from coding for a while. I have a movie database of personal movies to which I've added IMDB cinematographers and composers. So I have a join on main table MoviesXBMC with qryCinematographers and qryComposers.

I highlight / filter to see other movies by same composer.

When I unfilter, the view is reset to record one.

I wanted to create a piece of code to 1) select the primary key of the active record (while filtered) 2) set the filter property to false 3) go to the record active when I pressed the button.

I would assign a button to a macro which would runcode the module.

I can't remember the way to reference the immediate record's primary key. I tried:

Expand|Select|Wrap|Line Numbers
  1. Function CurrentRec()
  2.  
  3. Dim KEY As Variant
  4. With qryMovieCinemaComposer
  5.  
  6.    KEY = qryMovieCinemaComposer.KEY
  7.   .FilterOn = False
  8.   .Recordset.FindFirst "[KEY]=" & KEY
  9.  
  10. End With
  11. End Function
Thanks

John



Attached Images
File Type: jpg Unfiltered.jpg (54.1 KB, 433 views)
File Type: jpg unfiltered2.jpg (115.6 KB, 475 views)
File Type: jpg unfiltered3.jpg (124.1 KB, 570 views)
Jan 30 '19 #1
6 1328
twinnyfo
3,653 Expert Mod 2GB
Is this directly from the query? From a form in datasheet view?

If you are in a Form, the basic syntax for the index (based upon your example would be Me.KEY. Thus your code might look like this:

Expand|Select|Wrap|Line Numbers
  1. Private Function cmdUnfilterForm_Click()
  2.     Dim KEY As Variant
  3.  
  4.     With Me
  5.         KEY = .KEY
  6.        .FilterOn = False
  7.        .Recordset.FindFirst "[KEY]=" & KEY
  8.     End With
  9. End Function
This assumes you have a command button aptly named.
Jan 30 '19 #2
Yes, Twinnyfo it is basically simple query joins displayed as datasheets. It serves my purposes - I am simply trying to automate some simple repetitive actions.

For example, when I right-click a field and filter, I then want to remove the filter and have another active-filtered record be the active record in the full display. I could copy the key, then when I return search for that key.

I've been searching all day. Is there a way to programmaticly issue a 'go to' record command feeding it the key of the record active while under the filter. Something equivalent to 'ME' for forms.

Also, how do you reference the query's underlying table's value through code for a query that's been opened from the navigation pane.
Jan 31 '19 #3
twinnyfo
3,653 Expert Mod 2GB
What you are trying to do is not possible from a query. The data needs to be a record source on a form.
Jan 31 '19 #4
Rabbit
12,516 Expert Mod 8TB
To expand on twinnyfo's latest reply, you can replicate the query view as a form if you're looking to maintain that look and gain the functionality of a form.
Jan 31 '19 #5
I was hoping there was a hack to the query's hidden recordset!

I've been playing with a string of SendKeys (^c), ShowAllRecords, Sendkeys (^f, %n, ^v, %f) - to simulate manual keystrokes haha.

But the when the showAllRecords (or Filter=false) executes the value captured by ctrl-c on the filtered list gets lost!

I hope there is a system hack to get the address of the internal recordset to emulate 'with me.' functionality.

Thanks for your help.
Jan 31 '19 #6
twinnyfo
3,653 Expert Mod 2GB
I would recommend just creating a form based upon your query. This would allow you to do what you need to do without using SendKeys() or trying to foll the system into doing something it was never designed to do. Using a form gives you a tremendous amount of flexibility.
Jan 31 '19 #7

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

Similar topics

1
by: Agnes | last post by:
I got a dataset to be udpated. However, I need to filter some record first. E.g gljnheader.approval = "Y" I know I can use dataview to filter some record, but I don't know how to write the...
3
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer and the .net 2.0 framework. My intention is to send an email then insert the form's field values into an Access Table. I created a dataset called...
5
by: ConfusedMay | last post by:
I have 2 forms called Sales and SalesMeeting. Sales has all info about sales and it has primary ID called SalesID. SalesMeeting just an additional form that hold all the meeting for the particular...
3
by: newbieAl | last post by:
I have a stored procedure in mysql and I am calling it via a method and objectdatasource. I have two select methods. One that gets a list of employees and the other that gets one specific employee by...
2
by: geniussupreme | last post by:
hi guys need your help. im trying to save a record to another table. this is how it supposed to work... form1 (table_A) contains NameID, Age and other personal details. once clicked on the...
5
by: qwert1 | last post by:
I have 2 tables. table 1 looks like: Test1 Test2 Test3 0.6 0.1 0.5 0.4 0.4 0.3 0.2 0.8 0.5 table...
3
by: MOCaseA | last post by:
Hello, I am trying to generate a text field showing the number of forms available fo viewing after I use a filtering system to cut down the number of applicable records (i.e. I filter down from...
28
Brilstern
by: Brilstern | last post by:
Ok, I have a report that is opened up with a filter to a certain person's Equipment Custody Receipt card(ECR). Within this report are two subreports that are linked to the master field on the...
1
by: cehrfaee | last post by:
Hi! Please help me! How to create sql code .. Records from two tables do not match Thank You! Table 1 Per1 Per2 Per3 A1 B1 C1 A1 B1 C2 A1 B1 C3
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.