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

How to apply filter when opening a form

Hi all. I am trying to apply a filter in VBA to open a form. The filter fires on double click on a field value. I have got so far
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "TrackerEditFmDSFrm", 
  2. acNormal, , "AR_ID =" & AR_ID
This opens a message box displaying the AR_ID selected. But the user then needs to input the AR_ID. Can it be done so the filter runs using the selected value missing out the message box?
Jul 7 '10 #1

✓ answered by NeoPa

That is certainly much better Phil. There may be understandable mistakes in your answers but, as I say, they are understandable and not related to lack of effort on your part.

First let me say what I think is the solution, then I will try to answer any outstanding queries you may have.

Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub AR_ID_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "TrackerEditFmDSFrm", _
  4.                    acNormal, , _
  5.                    "AR_ID='" & AR_ID & "'"
  6.  
  7. End Sub
If a value for [AR_ID] can be non-numeric ("AR152" for example), then the field in the table is almost certainly a string field. String literals should be enclosed in quotes (Quotes (') and Double-Quotes (") - Where and When to use them). I've shown the code over three lines for clarity and visibility. It is not necessary to have it that way in your code, though it'll do no harm of course.
philqw78: I didn't consciously make one, unless a field put in a form is a control. The field(?) "AR_ID" is in the form, and that is what I am hoping to filter on.
Controls come in various shapes and sizes on a form. When fields are added to a form though, they are typically created as TextBox or other similar control, but importantly they are bound to an underlying field from the recordsource. Now, often these controls have the same name as the related (bound) field, but this is not necessarily so. The filter you apply when opening the form relates to the field, not the control. It is quite likely though, that this will not be obvious as the control could have the same name as the field.

Does that make things a little clearer for you?

9 16457
NeoPa
32,556 Expert Mod 16PB
philqw78: ... using the selected value missing out the message box?
What selected value are you referring to?

It can certainly be done, but helping you would require some understanding of what you're working with.
Jul 7 '10 #2
Sorry. I double click a value in the AR_ID field in a datasheet form view, say AR152. I want this value to filter the AR_ID in the form that is opened on doubleclick. What happens though is a message box appears, "Input Parameter", and the field value "AR152" is above the text box where it wants the parameter to be input.

Jul 7 '10 #3
NeoPa
32,556 Expert Mod 16PB
philqw78: I double click a value in the AR_ID field in a datasheet form view
This is a form you're talking about then I suppose. If you double-click a control on your form then there must surely be some code behind this. To have any idea of what is happening we would need to see the code.
Jul 7 '10 #4
The code for the double click on the form field is
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "TrackerEditFmDSFrm", acNormal, , "AR_ID =" & AR_ID
Jul 7 '10 #5
NeoPa
32,556 Expert Mod 16PB
We seem to be getting nowhere fast here. Try to avoid replying with the least information you could imagine being required. Give it some thought before posting. I'm not after the same code you've already posted. I'm looking for something with the information included that will save me asking you loads of questions about information you probably should have included with the question, but were understandably unaware of, as you don't have the experience that we have in knowing what is required.

I'm trying to make it easier for you, but you need to respond after first considering your reply.
  1. Please post the whole procedure that the code is within.
  2. Please explain what AR152 is. Bear in mind forms have controls and recordsets have fields.
  3. I assume the recordset (probably table) that your form [TrackerEditFmDSFrm] is bound to has a field called [AR_ID]. Please confirm.
  4. Is there actually a control on your form [TrackerEditFmDSFrm] called [AR_ID]?
If there is anything here you don't understand, don't be afraid to say so. Communication is the key. Good communication makes for much easier progress. The reverse is also true of course.
Jul 8 '10 #6
@NeoPa
Sorry Neo. I am probably trying to run before I can even crawl here.
  1. The whole procedure is
    Expand|Select|Wrap|Line Numbers
    1. Private Sub AR_ID_DblClick(Cancel As Integer)
    2.  
    3. DoCmd.OpenForm "TrackerEditFmDSFrm", acNormal, , "AR_ID =" & AR_ID
    4.  
    5. End Sub
  2. AR152 is the value in the "AR_ID" field/control of a single record.
  3. Yes the field AR_ID is in the "Tracker" table. The form "TrackerDSfrm" looks at this table . (And some bound fields from another table, these are bound on a lookup combo for AR_ID). This is the form that I use the double click in. (Hoping that the double click would open "TrackerEditFmDSFrm" at the selected double clicked record)
  4. I didn't consciously make one, unless a field put in a form is a control. The field(?) "AR_ID" is in the form, and that is what I am hoping to filter on.
There are lots of things I don't understand. I'm slowly trying to fight my way through them. What is your definition of a control. To me they are the buttons I can put on a form and add some action or macro to them. This is where my answers above may be wrong.
Hopefully this is a bit clearer.
Jul 8 '10 #7
NeoPa
32,556 Expert Mod 16PB
That is certainly much better Phil. There may be understandable mistakes in your answers but, as I say, they are understandable and not related to lack of effort on your part.

First let me say what I think is the solution, then I will try to answer any outstanding queries you may have.

Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub AR_ID_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "TrackerEditFmDSFrm", _
  4.                    acNormal, , _
  5.                    "AR_ID='" & AR_ID & "'"
  6.  
  7. End Sub
If a value for [AR_ID] can be non-numeric ("AR152" for example), then the field in the table is almost certainly a string field. String literals should be enclosed in quotes (Quotes (') and Double-Quotes (") - Where and When to use them). I've shown the code over three lines for clarity and visibility. It is not necessary to have it that way in your code, though it'll do no harm of course.
philqw78: I didn't consciously make one, unless a field put in a form is a control. The field(?) "AR_ID" is in the form, and that is what I am hoping to filter on.
Controls come in various shapes and sizes on a form. When fields are added to a form though, they are typically created as TextBox or other similar control, but importantly they are bound to an underlying field from the recordsource. Now, often these controls have the same name as the related (bound) field, but this is not necessarily so. The filter you apply when opening the form relates to the field, not the control. It is quite likely though, that this will not be obvious as the control could have the same name as the field.

Does that make things a little clearer for you?
Jul 8 '10 #8
Thanks Neo. Thats excellent. And today wasn't wasted as I learnt something.
Jul 8 '10 #9
NeoPa
32,556 Expert Mod 16PB
Good for you :)

A day's never wasted if you learn something.
Jul 8 '10 #10

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

Similar topics

1
by: Paul Fairless | last post by:
I have a form called frmCustSearch to search for customers against an SQL Server database. The form contains a simple textbox into which the Customers surname is typed, and a datagrid then...
0
by: choste11 | last post by:
I just installed VB.NET on a PC running Windows XP. The install went fine, but when I start a new project and try and open form1.vb by either double clicking it or right click, View Desginer, I get...
0
by: Ronald Colijn via .NET 247 | last post by:
Hello all you people, Thanks for reading this. I hve a strange thing which annoys me noend. I am using VS.NET with MS-Access DB, framework version 1.1,Windows XP Pro, IIS 5.1. In my webforms I...
3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
2
by: Ray | last post by:
Stop me if you've heard this, but I am running Access 2002 and all of a sudden, if I design a particular form (it's been working fine for ages), Access crashes rather than open it in design view. ...
2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
0
by: melanieab | last post by:
Hi, I can't begin to understand this one. I have a form with a tabcontrol. When I first enter one of the pages (whether by tabbing or opening the form), I say to focus on a button. It does focus...
4
by: dstorms | last post by:
Hi, I'm trying to create a form with a list box with 2 columns and a button that opens the selected record in the appropriate form. In the sample below, the first column lists the type of equipment...
2
DonRayner
by: DonRayner | last post by:
This one has me stumped. I'm getting a "Type Mismatch" error on one of my forms when it's being opened. It's hapening before the forms "On Open" event, I stuck a msgbox in there to check and I'm...
2
by: sap01 | last post by:
Hi All, I want to display the data from a table by applying filter in the form. I want three combo box filter in the form. If I select all the three then it should display the data in the form from...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.