473,834 Members | 2,362 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get a second data field from a list box?

25 New Member
Hi there,

I'm developing a database for my company, and for the most part I've been successful, with some complex sub-routines already working fine. But this one has me stumped!

Some background on this database:

It has numerous and tables and queries, and a few tables have identical field names, and I've created a union query, named QryItemList, to create a list containing the unique identifier number in UniqueID, and included the field CategoryName. Then I created a form with a listbox, labeled ListBoxData, and a button that starts this sub-routine when clicked.

The intended result was open the appropriate form, determined by CategoryName, to the record filtered by UniqueID. Unfortunately the listbox only returns the value for UniqueID, and I've been trying to find a way to get the CategoryName data also. The latest attempt was to create a temporary table that I could append the recordset, and use the CategoryName from the temporary table to complete the sub-routine.

When I clicked on the button I get the rather unhelpful "Object required" error message. Can anyone help me with this code?

A successful subroutine would enable the user to open several different forms from one list and open the correct record in one step instead of two. It may not seem like much of a big deal, but when the list is long and varied it can reduce the action of opening and closing of forms by 75% or more.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ItemSelect_Click()
  2. On Error GoTo Err_ItemSelect_Click
  3.  
  4. '1. Set variables for sub-routine
  5. Dim stDocName As String
  6. Dim stLinkCriteria As String
  7. Dim stCategory As String
  8.  
  9. Dim strSQL As String
  10. Dim strTableName As String
  11. Dim strLinkCriteria2 As String
  12.  
  13. '2. Set value of CategoryName according to value of UniqueID
  14. '      QryItemList is a union query of 3 tables with common fields
  15. strLinkCriteria2 = "QryItemList.UniqueID=" & "'" & Me![ListBoxData] & "'"
  16.  
  17. strSQL = "INSERT INTO tblTemp " & _
  18.     "SELECT QryItemList.UniqueID, QryItemList.CategoryName " & _
  19.     "FROM QryItemList " & _
  20.     "WHERE " & strLinkCriteria2 & ";"
  21.  
  22. DoCmd.SetWarnings False
  23. DoCmd.RunSQL strSQL
  24. DoCmd.SetWarnings True
  25.  
  26. '3. Match CategoryName to correspondaing form name
  27. stCategory = QryItemList.CategoryName
  28. If stCategory = "Category1" Then
  29.         stDocName = "frmCategory1"
  30.     ElseIf stCategory = "Category2" Then
  31.         stDocName = "frmCategory2"
  32.     ElseIf stCategory = "Category3" Then
  33.         stDocName = "frmCategory3"
  34. End If
  35.  
  36. '4. Open form according to CategoryName and record according to UniqueID
  37. stLinkCriteria = "[UniqueID]=" & "'" & Me![ListBoxData] & "'"
  38. DoCmd.OpenForm stDocName, , , stLinkCriteria
  39.  
  40. '5. Delete temporary table before exiting the sub-routine
  41. db.TableDefs.Delete ("tblTemp")
  42.  
  43. Exit_ItemSelect_Click:
  44.     Exit Sub
  45.  
  46. Err_ItemSelect_Click:
  47.     MsgBox Err.Description
  48.     Resume Exit_ItemSelect_Click
  49.  
  50. End Sub
  51.  
Oct 30 '07 #1
3 2070
Rabbit
12,516 Recognized Expert Moderator MVP
I didn't read the entire post but I think you're looking for:
Expand|Select|Wrap|Line Numbers
  1. Me.lstBoxName.Columns(Index)
Where index is a number from 0 to number of columns minus 1.
Oct 30 '07 #2
dstorms
25 New Member
I didn't read the entire post but I think you're looking for:
Expand|Select|Wrap|Line Numbers
  1. Me.lstBoxName.Columns(Index)
Where index is a number from 0 to number of columns minus 1.
Thanks Rabbit!

The revised code is much simpler and works just fine. I did have to use the singular "Comlumn(1) " instead of the plural "Columns(1) " above in order for it to work.

Here's the modified code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ItemSelect_Click()
  2. On Error GoTo Err_ItemSelect_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6. Dim stCategory As String
  7.  
  8. stCategory = Me.ListBoxData.Column(1) ' <-- Uses Data in second column 
  9.  
  10. If stCategory = "Category1" Then
  11.         stDocName = "frmCategory1"
  12.     ElseIf stCategory = "Category2" Then
  13.         stDocName = "frmCategory2"
  14.     ElseIf stCategory = "Category3" Then
  15.         stDocName = "frmCategory3"
  16. End If
  17.  
  18. stLinkCriteria = "[UniqueID]=" & "'" & Me![ListBoxData] & "'"
  19. DoCmd.OpenForm stDocName, , , stLinkCriteria
  20.  
  21. Exit_ItemSelect_Click:
  22.     Exit Sub
  23.  
  24. Err_ItemSelect_Click:
  25.     MsgBox Err.Description
  26.     Resume Exit_ItemSelect_Click
  27.  
  28. End Sub
  29.  
Thank you for your help!
Oct 31 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck.
Oct 31 '07 #4

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

Similar topics

9
17611
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like array_reverse(). Can anyone tell me why?
0
1301
by: johnny | last post by:
hi all, I have an old script which has a dynamically populated form where the user chooses the items from as many list/menu as the categories existing in the database and then on a confirm page only the items selected are shown to be checked by the user before sending them ( to a third script ) Now I would like to add another list/menu field in the form to let the user choosing the quantity of each item selected, but I don't know how
5
2405
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and relevant announcements. If you're interested, drop me a note. But if for some reason you think that this discussion is fine here at the c.l.py, please let me know. ** LONG POST AHEAD **
30
3146
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and wish that my predecessor had followed) but -- alas -- being a relative beginner to Access, I can't see the reasoning behind one of the points and the site does not provide any rationale / explanation for its presence either: 2. Thou shalt never...
2
1567
by: Big Time | last post by:
Hi, I have a question regarding using drop down lists and how to get them to limit the list of a subsequent field. I have a database which has the names of colleges. Each college has it's own set of specific courses. All the colleges are in my Institutions table, and all the course codes are in my Course Codes table and are related based on InstitutionID. On my form, when a user inputs the InstitutionID of a particular college, I...
4
3869
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system that doesn't offer dynamic memory allocation (to be clear: no malloc, no realloc), and with rather tight memory constraints. Writing my own malloc to do dynamic allocation from some static pool isn't really an option, for various reasons, not...
13
4187
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture' , data type='Number' ,Display Control='Combo Box', RowSource Type = 'Value List' and Row Source = ' 0;"chair";1;"Table";2;"Bed" ' Therefore, in data sheet view of table, if we select (1 : Table ) ,
1
2779
by: kickergirl | last post by:
I have a database developed in MS Access 2000 that allows people to enter training histories for staff. The staff information is stored in tblStaff, and the training histories are stored in tblTraining. The main form (frmDataEntry) contains the staff contact information and a continuous subform displaying the selected staff's training history. The desire was for the ability to allow the data entry person to search the database by staff's...
4
4594
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
9796
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
9643
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10786
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
10503
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
10544
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
10214
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
7754
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
5624
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
3079
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.