473,800 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating a list box, filtered with values from the form

6 New Member
I have 3 tables, Actions, Objects and AO, where "AO" a table that relates Actions and Objects, each row is a pair the other tables' keys)

I have a form that is generated with values from Objects, each form page only shows info on one Object. What I would like to do is to add a list box that shows what Actions are available for this Object.

I would guess that the listbox would have to be populated by the query
"select Actions.* from Actions Inner join AO on Actions.key = AO.Akey inner join Objects on Objects.key = AO.BKey where Objects.Key = [filter]"

And the [filter] value would be the current form page's Object's key, but how can I get it?

How can I do this?

Thanks in advance
Mar 9 '08 #1
5 2765
NeoPa
32,579 Recognized Expert Moderator MVP
I'm assuming that AKey & BKey are both string fields. If they are numeric you need to remove the quotes (') and change line #6. If they are dates then you really should have said so in the question :D
Expand|Select|Wrap|Line Numbers
  1. ...
  2.   strSQL = "SELECT Actions.* " & _
  3.            "FROM [Actions] INNER JOIN [AO] " & _
  4.            "  ON Actions.Key=AO.AKey " & _
  5.            "WHERE AO.BKey='%F'"
  6.   strSQL = Replace(strSQL, "%F", Split(Me.Filter, "'")(1))
  7.   lstActions.RowSource = strSQL
Let us know how you get on with this.
Mar 10 '08 #2
inepu
6 New Member
I want the listbox to be populated as I open the form, not with VBA from some event

When you right click the listbox in edit mode, and go to properties, there you can choose the row source to be a table or query you want, right? But I want this query to be filtered with one field from the form that is opened.

Assuming the form is populated by the query:
Select Objects.Key, Objects.Field1; Objects.Field2 from Objects

I want the list box to be populated by the query
select Actions.* from Actions Inner join AO on Actions.key = AO.Akey where AO.OKey = Me![Objects.Key]

If I was using VBA on some event to populate the list box that woud work, but in the listbox's rowsource properties that doesn't work, when I open the form I get a pop up asking me what the value of Me![Objects.Key] is
Mar 14 '08 #3
NeoPa
32,579 Recognized Expert Moderator MVP
I want the listbox to be populated as I open the form, not with VBA from some event
I'll assume you were not trying to be rude or ungrateful here, but if that's what you wanted, why did you not say so in the first place and save me wasting my time finding a solution that matched the question you asked, but not what you wanted. We may offer our time voluntarily, but that's no reason to treat it as valueless.

If you want this to work in the narrow way specified, you will need to reference the control on the form explicitly. This involves using the name of the form as well as the name of the control (which would appear to be [Objects.Key]) and is not an internal reference (Me. won't work).

Unless you post the name of the form I am unable to show you how this should be done specifically, but in general it would be something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT Actions.*
  2. FROM [Actions] INNER JOIN [AO]
  3.   ON Actions.Key=AO.AKey
  4. WHERE AO.BKey=Forms!YourFormName.[Objects.Key]
Mar 15 '08 #4
inepu
6 New Member
If I seemed rude I'm sorry, not my intention. I also thought my first question was explicit... And I'm not providing my tables and forms' names because it's all in portuguese and I'd rather learn from a general example than a specific one, also wasting less time explaining the relationship between the 3 tables just because the names are confusing to people other than me.

But, I had already tried the way you've proposed now, and it doesn't work. It either returns "Invalid bracketing of the Forms!F_Actions .[Objects.Key] or if I don't use the square brackets it asks me what the value of "Forms!F_Action s.Objects.Key" is. I've tried several combinations of exclamations points and periods and brackets, none work.

And by "some VBA event" I meant I was looking for a way to have the list displayed as I open each form record, not by pressing a button (or something like that)

I know I can make a subform with textboxes and continuous results, giving me a similar visual effect of what I want (and access provides an easy way to connect a field from the form and the subform). But I need to use a listbox so that the results are multi-selectable

If you are thinking about possible problems in language syntax, Access translates automatically "Forms" to "Formulário s", so the problem is not there.

-----

As I was writing my post, I found out the answer to my problem, but decided to keep the previous text, just so you can see I didn't intended to be disrespectful to your work, but also that It was not only my fault we had an misunderstandin g.

The solution I found was in fact with VBA, and using an event I did not know about.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  strSQL = "select Actions.* <etc etc> where AO.BKey = " & Me![Objects.Key]
  3.  myListBox.RowSource = strSQL
  4. End Sub
That's it and it works, pretty much what you posted the first time, although I didn't understand what the Split was for and didn't know that a Form_Current() existed

sorry of all the trouble and thanks
Mar 15 '08 #5
NeoPa
32,579 Recognized Expert Moderator MVP
Firstly let me say that I'm sure there was no intention to be rude. Sometimes it appears that way when people have to translate their ideas into English from another language (Portuguese is not the most similar language to English) so I'm glad I made the assumption that this was not your intention. Thank you for clarifying anyway.

Names :
Names can be confusing, as you say, but they are also helpful to someone answering a question as they save that person from having to invent their own, or keep explaining that what they've shown is in place of a name.
Consider :
Expand|Select|Wrap|Line Numbers
  1. Me.[asdfgh].Visible = True
...is easier to write AND read than :
Expand|Select|Wrap|Line Numbers
  1. Me.[Insert your control name here].Visible = True
...and where there's more than a single reference to an object it's more complicated still.

Please don't consider this as criticism, just as a view from the other side. Something simple to you can nevertheless be quite complicated from here, and leaving item names out is one of those things.

I appreciate that you're looking for a general answer, to learn, rather than a specific answer which only helps in this one case. If you have any difficulty getting the general lesson from a specific answer we are always happy to clarify.

Events in Access :
There are two which you may be interested in here :
Expand|Select|Wrap|Line Numbers
  1. Form_Open(Cancel As Integer)
  2. Form_Current()
The first triggers every time the form is opened. The second triggers every time a new record becomes the current one. I will leave you to determine which of these is more correct for your needs. It seems to me that maybe the Open is more correct, but I don't know your project as well as you do so you decide which is the better one to use.

Split() Function :
This is a neat little function (paired with the Join() function) which processes through a string and separates out each element into an array based on the separator character supplied.
Consider the string "[MyStringField] = 'Blob'".
Expand|Select|Wrap|Line Numbers
  1. Split("[MyStringField] = 'Blob'")
...returns an array with three string elements in it numbered from 0.
0 = "[MyStringField] = "
1 = "Blob"
2 = ""
We are interested in the string in between the quotes (') which is "Blob".
Expand|Select|Wrap|Line Numbers
  1. Split("[MyStringField] = 'Blob'")(1) == "Blob"
And lastly, thank you for replying and letting us know that you've found an answer that you're happy with.

Welcome to TheScripts :)
Mar 16 '08 #6

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

Similar topics

3
3591
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. I need to be able to send to a stored procedure the areas that the client has selected so these can be stored in the database.
1
266
by: Jonny | last post by:
Hello, Firstly, I fill in a form for each record, which contains things like name, date from, date to etc. I have a list form in my database, which when opened displays certain information from my records (name, date from, date to etc). I also have a few text boxes on the list form, which when text is entered into them, the list box on the form is filtered accordingly
3
1474
by: Karl Roes | last post by:
Hi All, I would also like some help with form filtered differences in totals. I have a main form for the client, and a continuous subform listing client transactions. The subform can be filtered by several fields. I have set up several text boxes which programatically show various OnCurrent subtotal details depending on the filtered options in the continuous subform.
3
6044
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is "LabLocation_ID". With an existing lab, they then need to add the members for that lab. So, what I am trying to do is the following. With the FormView of the Lab open, the user will click a button to open a FormView (InsertMode) and add a new...
1
1598
by: sparks | last post by:
I have a main table with teacher names and students I can put this in a subform and filter by teacher name so I have a list of her students in a sub form. the problem I have is this is created in tblmain but now I need to have them enter data each day for each student so I have a new table tbldata that has TimeStart, TimeEnd how can I make a list of students in a subform like I have now created from tblmain, and filtered(so far so...
3
3464
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: Access 2002 front-end using SQL Server 2000 (MSDE actually) via ADP/ADE Access Data Project.
13
3552
by: Mary | last post by:
I'll pulling my hair out on this one and would be so appreciative of any help. I am creating a data entry form to enter results of a student survey. There are 40 questions on the survey. The first 7 have to do with respondent information like grade, class and age. I have those in a table with a PK of RespondentId, which is autonumbered. Questions 8-40 all have the same format. For these questions I have a table set up with the...
0
1706
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which...
3
2407
by: Thelma Roslyn Lubkin | last post by:
I have a form whose rowsource is a single table, i.e. 'Datasystem'. I use a combobox to search for records in that table based on the value of a single field, i.e., 'systemname'. I use a multi-select listbox to filter the form on a different field, i.e. 'domain', so that the filtered form can have several allowed values of this field
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.