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: -
Private Sub ItemSelect_Click()
-
On Error GoTo Err_ItemSelect_Click
-
-
'1. Set variables for sub-routine
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
Dim stCategory As String
-
-
Dim strSQL As String
-
Dim strTableName As String
-
Dim strLinkCriteria2 As String
-
-
'2. Set value of CategoryName according to value of UniqueID
-
' QryItemList is a union query of 3 tables with common fields
-
strLinkCriteria2 = "QryItemList.UniqueID=" & "'" & Me![ListBoxData] & "'"
-
-
strSQL = "INSERT INTO tblTemp " & _
-
"SELECT QryItemList.UniqueID, QryItemList.CategoryName " & _
-
"FROM QryItemList " & _
-
"WHERE " & strLinkCriteria2 & ";"
-
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
-
'3. Match CategoryName to correspondaing form name
-
stCategory = QryItemList.CategoryName
-
If stCategory = "Category1" Then
-
stDocName = "frmCategory1"
-
ElseIf stCategory = "Category2" Then
-
stDocName = "frmCategory2"
-
ElseIf stCategory = "Category3" Then
-
stDocName = "frmCategory3"
-
End If
-
-
'4. Open form according to CategoryName and record according to UniqueID
-
stLinkCriteria = "[UniqueID]=" & "'" & Me![ListBoxData] & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
'5. Delete temporary table before exiting the sub-routine
-
db.TableDefs.Delete ("tblTemp")
-
-
Exit_ItemSelect_Click:
-
Exit Sub
-
-
Err_ItemSelect_Click:
-
MsgBox Err.Description
-
Resume Exit_ItemSelect_Click
-
-
End Sub
-
3 2070 Rabbit 12,516
Recognized Expert Moderator MVP
I didn't read the entire post but I think you're looking for: - Me.lstBoxName.Columns(Index)
Where index is a number from 0 to number of columns minus 1.
I didn't read the entire post but I think you're looking for: - 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: -
Private Sub ItemSelect_Click()
-
On Error GoTo Err_ItemSelect_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
Dim stCategory As String
-
-
stCategory = Me.ListBoxData.Column(1) ' <-- Uses Data in second column
-
-
If stCategory = "Category1" Then
-
stDocName = "frmCategory1"
-
ElseIf stCategory = "Category2" Then
-
stDocName = "frmCategory2"
-
ElseIf stCategory = "Category3" Then
-
stDocName = "frmCategory3"
-
End If
-
-
stLinkCriteria = "[UniqueID]=" & "'" & Me![ListBoxData] & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_ItemSelect_Click:
-
Exit Sub
-
-
Err_ItemSelect_Click:
-
MsgBox Err.Description
-
Resume Exit_ItemSelect_Click
-
-
End Sub
-
Thank you for your help!
Rabbit 12,516
Recognized Expert Moderator MVP
Not a problem, good luck.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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
|
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 **
|
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...
|
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...
| |
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...
|
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 ) ,
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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...
| |