473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching records using a list box.

10 New Member
I'm currently using access 97. I'm relatively new to all this, so have attempted to create a company Asset Register when i've come across a problem im unsure of. I'm trying to create some sort of search finder that enables me to navigate to the fields i require quickly.
I've done this using a list box with FirstName, LastName and PCNumber as the search headings. Above that are a set of command buttons that search both ascending and descending. When highlighting the required user and hitting search the following comes up 'Enter Parameter Value' Assets.AssetID. It's more complicated than what i've put so is there a way i can attach the DB ?
Oct 16 '06 #1
3 2549
MMcCarthy
14,534 Recognized Expert Moderator MVP
Post the code behind the search buttons.



I'm currently using access 97. I'm relatively new to all this, so have attempted to create a company Asset Register when i've come across a problem im unsure of. I'm trying to create some sort of search finder that enables me to navigate to the fields i require quickly.
I've done this using a list box with FirstName, LastName and PCNumber as the search headings. Above that are a set of command buttons that search both ascending and descending. When highlighting the required user and hitting search the following comes up 'Enter Parameter Value' Assets.AssetID. It's more complicated than what i've put so is there a way i can attach the DB ?
Oct 16 '06 #2
dlowry
10 New Member
Post the code behind the search buttons.
Option Compare Database
Option Explicit
Private Function basOrderby(col As String, xorder As String) As Integer
Dim strSQL As String

'Clear captions from command buttons
ClearCaptions

'Set row source for list box
strSQL = "SELECT DISTINCTROW AssetID, AssetsFirstName, AssetsLastName, PCNumber "
strSQL = strSQL & "FROM Assets "
strSQL = strSQL & "ORDER BY " & col & " " & xorder
Me!lstSearch.RowSource = strSQL
Me!lstSearch.Requery

End Function

Sub ClearCaptions()

'Clear captions of asc and desc symbols

Me!cmdOrderFNameDesc.Caption = "Order by First Name"
Me!cmdOrderFName.Caption = "Order by First Name"
Me!cmdOrderLNameDesc.Caption = "Order by Last Name"
Me!cmdOrderLName.Caption = "Order by Last Name"
Me!cmdOrderPCNumberDesc.Caption = "Order by PCNumber"
Me!cmdOrderPCnumber.Caption = "Order by PCNumber"

End Sub

Private Sub cmdOrderFName_Click()
'Set First Name order in ascending order and apply captions
Dim response As Integer
response = basOrderby("AssetFirstName", "asc")
Me!cmdOrderFNameDesc.Visible = True
Me!cmdOrderFNameDesc.Caption = "v Order by First Name v"
Me!cmdOrderFNameDesc.SetFocus
Me!cmdOrderFName.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderFNameDesc_Click()
'Set First Name order in descending order and apply captions
Dim response As Integer
response = basOrderby("AssetFirstName", "DESC")
Me!cmdOrderFName.Visible = True
Me!cmdOrderFName.Caption = "^ Order by First Name ^"
Me!cmdOrderFName.SetFocus
Me!cmdOrderFNameDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderLName_Click()
'Set Last Name order in ascending order and apply captions
Dim response As Integer
response = basOrderby("AssetLastName", "asc")
Me!cmdOrderLNameDesc.Visible = True
Me!cmdOrderLNameDesc.Caption = "v Order by First Name v"
Me!cmdOrderLNameDesc.SetFocus
Me!cmdOrderLName.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderLNameDesc_Click()
'Set Last Name order in descending order and apply captions
Dim response As Integer
response = basOrderby("AssetLastName", "DESC")
Me!cmdOrderLName.Visible = True
Me!cmdOrderLName.Caption = "^ Order by Last Name ^"
Me!cmdOrderLName.SetFocus
Me!cmdOrderLNameDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderPCNumber_Click()
'Set PN order in ascending order and apply captions
Dim response As Integer
response = basOrderby("PCNumber", "asc")
Me!cmdOrderPCNumberDesc.Visible = True
Me!cmdOrderPCNumberDesc.Caption = "v Order by PCNumber v"
Me!cmdOrderPCNumberDesc.SetFocus
Me!cmdOrderPCnumber.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderPCNumberDesc_Click()
'Set PN order in descending order and apply captions
Dim response As Integer
response = basOrderby("PCNumber", "DESC")
Me!cmdOrderPCnumber.Visible = True
Me!cmdOrderPCnumber.Caption = "^ Order by PCNumber ^"
Me!cmdOrderPCnumber.SetFocus
Me!cmdOrderPCNumberDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub lstSearch_AfterUpdate()
'Once a record is selected in the list, enable the showRecord button
ShowRecord.Enabled = True
End Sub

Private Sub lstSearch_DblClick(Cancel As Integer)
'If the user double-clicks in the list, act as though
'the ShowRecord button was clicked
If Not IsNull(lstSearch) Then
ShowRecord_Click
End If
End Sub

Private Sub ShowRecord_Click()
'Find a selected record, then close the search dialog box

DoCmd.OpenForm "Assets", , , _
"Assets.AssetID=" & "'" & Me.lstSearch.Column(0) & "'"

'Close the dialog box
DoCmd.Close acForm, "frmListBoxSearch"

End Sub
Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click
'Cancel and close the form

DoCmd.Close

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub
Oct 17 '06 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
This is your problem line I think.

DoCmd.OpenForm "Assets", , , _
"Assets.AssetID=" & "'" & Me.lstSearch.Column(0) & "'"

Go to the Assets form and in design view go to the properties of the control you think is AssetID. Look under the other tab for the system name of the control. I think you will find it is not Assets.AssetID.



Option Compare Database
Option Explicit
Private Function basOrderby(col As String, xorder As String) As Integer
Dim strSQL As String

'Clear captions from command buttons
ClearCaptions

'Set row source for list box
strSQL = "SELECT DISTINCTROW AssetID, AssetsFirstName, AssetsLastName, PCNumber "
strSQL = strSQL & "FROM Assets "
strSQL = strSQL & "ORDER BY " & col & " " & xorder
Me!lstSearch.RowSource = strSQL
Me!lstSearch.Requery

End Function

Sub ClearCaptions()

'Clear captions of asc and desc symbols

Me!cmdOrderFNameDesc.Caption = "Order by First Name"
Me!cmdOrderFName.Caption = "Order by First Name"
Me!cmdOrderLNameDesc.Caption = "Order by Last Name"
Me!cmdOrderLName.Caption = "Order by Last Name"
Me!cmdOrderPCNumberDesc.Caption = "Order by PCNumber"
Me!cmdOrderPCnumber.Caption = "Order by PCNumber"

End Sub

Private Sub cmdOrderFName_Click()
'Set First Name order in ascending order and apply captions
Dim response As Integer
response = basOrderby("AssetFirstName", "asc")
Me!cmdOrderFNameDesc.Visible = True
Me!cmdOrderFNameDesc.Caption = "v Order by First Name v"
Me!cmdOrderFNameDesc.SetFocus
Me!cmdOrderFName.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderFNameDesc_Click()
'Set First Name order in descending order and apply captions
Dim response As Integer
response = basOrderby("AssetFirstName", "DESC")
Me!cmdOrderFName.Visible = True
Me!cmdOrderFName.Caption = "^ Order by First Name ^"
Me!cmdOrderFName.SetFocus
Me!cmdOrderFNameDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderLName_Click()
'Set Last Name order in ascending order and apply captions
Dim response As Integer
response = basOrderby("AssetLastName", "asc")
Me!cmdOrderLNameDesc.Visible = True
Me!cmdOrderLNameDesc.Caption = "v Order by First Name v"
Me!cmdOrderLNameDesc.SetFocus
Me!cmdOrderLName.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderLNameDesc_Click()
'Set Last Name order in descending order and apply captions
Dim response As Integer
response = basOrderby("AssetLastName", "DESC")
Me!cmdOrderLName.Visible = True
Me!cmdOrderLName.Caption = "^ Order by Last Name ^"
Me!cmdOrderLName.SetFocus
Me!cmdOrderLNameDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderPCNumber_Click()
'Set PN order in ascending order and apply captions
Dim response As Integer
response = basOrderby("PCNumber", "asc")
Me!cmdOrderPCNumberDesc.Visible = True
Me!cmdOrderPCNumberDesc.Caption = "v Order by PCNumber v"
Me!cmdOrderPCNumberDesc.SetFocus
Me!cmdOrderPCnumber.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub cmdOrderPCNumberDesc_Click()
'Set PN order in descending order and apply captions
Dim response As Integer
response = basOrderby("PCNumber", "DESC")
Me!cmdOrderPCnumber.Visible = True
Me!cmdOrderPCnumber.Caption = "^ Order by PCNumber ^"
Me!cmdOrderPCnumber.SetFocus
Me!cmdOrderPCNumberDesc.Visible = False
Me!lstSearch.SetFocus

End Sub

Private Sub lstSearch_AfterUpdate()
'Once a record is selected in the list, enable the showRecord button
ShowRecord.Enabled = True
End Sub

Private Sub lstSearch_DblClick(Cancel As Integer)
'If the user double-clicks in the list, act as though
'the ShowRecord button was clicked
If Not IsNull(lstSearch) Then
ShowRecord_Click
End If
End Sub

Private Sub ShowRecord_Click()
'Find a selected record, then close the search dialog box

DoCmd.OpenForm "Assets", , , _
"Assets.AssetID=" & "'" & Me.lstSearch.Column(0) & "'"

'Close the dialog box
DoCmd.Close acForm, "frmListBoxSearch"

End Sub
Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click
'Cancel and close the form

DoCmd.Close

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub
Oct 17 '06 #4

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

Similar topics

10
5459
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
3
1471
by: aaj | last post by:
This is a simple question compared to some of the stuff that gets asked (and answered) here, but sometimes its easy to over look the simpler things. I've been working with databases for a few...
3
2392
by: Mark Line | last post by:
Hello! I'm a python n00b! I've been writing in c++ for a few years so programming's not new to me, just python that I don't know the syntax!
3
2790
by: Simone | last post by:
Hi All, I have a Find Record button setup in most of my forms in order to find a specific customer's details. I have just noticed today though that this search will only find the customer if it...
33
2432
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
6
1697
by: Advo | last post by:
Hi Basically, i need to write a php search function which will search all our pages in the directory depending on user keywords.. the thing is, this could be difficult as we may have 8000+...
1
1847
by: BlackJackal | last post by:
Alright here is the problem I have for homework. I understand most of it but I am not exactly sure what the problem is asking me to do or how to search the seperate arrays using the account number...
7
4529
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
4
5320
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
1
8262
by: remya1000 | last post by:
I’m using VB.net 2003 application program. I am trying to do a select statement whereby I'm searching between 2 datetime values that are being stored as datetime. records are stored inside...
0
7193
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
7067
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
7264
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
7316
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...
1
6975
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
7449
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...
1
4992
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...
0
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.