In some previous posts I was inquiring about record set order, thanks everyone for the help it fixed the problem. With that step out of the way I am having an problem with the next step.
So I search the DB for John Doe, and I get three results and have them listed in a Listbox: - ID First Name Last Name
-
4 John Doe
-
23 John Doe
-
58 John Doe
Now I want to click an entry and have that John Doe's record show up. - Private Sub lstSearchResults_Click()
-
Dim dbs As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim ci As String
-
Dim ctl As Control
-
-
Set dbs = CurrentDb
-
-
Set ctl = lstSearchResults
-
'ci = ctl.ItemsSelected.Item(1)
-
-
lstSearchResults.AddItem (ci)
-
-
'Dim strSQL As String
-
'strSQL = "Select * FROM Request WHERE Customer_Order_Number = " & lstSearchResults.ItemsSelected.Item(1) 'lstSearchResults.ItemData(1)
-
'Set qdf = dbs.CreateQueryDef("GetRequest", strSQL)
-
-
DoCmd.OpenForm ("Current_Customer_Data")
-
End Sub
My code has a lot of comments because I have been playing around. It "worked" when I used lstSearchResults.ItemData.Item(1). But this only retrieved the first item from the list. I have, as you can see from my code tried to use lstSearchResults.ItemSelected but the rest is still gray for me.
Anybody follow and can help? Please let me know.
Thank you.
19 3418
Assuming that ID is the first column in your listbox. - DoCmd.OpenForm "Current_Customer_Data",,,"ID = " & Me.lstSearchResults.Column(0)
Cool.
Is Me a reserved word or should I replace that with my Form name? Because when I put my form name in it, it does not work, but when I leave Me in it kinda works.
It still opens the record to the first John Doe on the list, even if I click, highlight, and select the third one?
Cool.
Is Me a reserved word or should I replace that with my Form name? Because when I put my form name in it, it does not work, but when I leave Me in it kinda works.
It still opens the record to the first John Doe on the list, even if I click, highlight, and select the third one?
Yes Me is a reserved word pointing to the form that called the event.
It should open correctly if the Where criteria is set up correctly. Check the field names and control names and position in the listbox to make sure everything is referencing correctly.
NeoPa 32,556
Expert Mod 16PB
It still opens the record to the first John Doe on the list, even if I click, highlight, and select the third one?
Post in the Row Source for your ListBox and we can check it over for you.
If you include the exact (pasted) code for opening the form too we'll check that as well.
- If ((FirstName <> "") And (LastName <> "")) Then
-
Set rs = dbs.OpenRecordset("Select * FROM Caller WHERE C_F_Name like '" & FirstName & "*' and C_L_Name like '" & LastName & "*'")
-
End If
-
-
If (((FirstName = "") And (LastName = "")) Or ((FirstName = "") And (LastName <> "")) Or ((FirstName <> "") And (LastName = ""))) Then
-
lblerror1.Visible = True
-
lblError2.Visible = False
-
Else
-
If (rs.EOF) Then
-
lblerror1.Visible = False
-
lblError2.Visible = True
-
Call_ID = ""
-
Telephone = ""
-
Email = ""
-
Dist_ID = ""
-
'lstSearchResults.RemoveItem (1)
-
check1 = False
-
-
Else
-
lblerror1.Visible = False
-
lblError2.Visible = False
-
-
lstSearchResults.RowSource = "Value List"
-
lstSearchResults.ColumnCount = 4
-
lstSearchResults.RowSource = "Customer ID; First Name; Last Name; Distributor"
-
-
While (Not rs.EOF)
-
Dim row As String
-
row = rs(0) & ";" & rs(1) & ";" & rs(2) & ";" & rs(5)
-
lstSearchResults.AddItem (row)
-
rs.MoveNext
-
Wend
-
End If
-
End If
-
End Sub
-
-
Private Sub lstSearchResults_Click()
-
Dim dbs As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim ci As String
-
Dim ctl As Control
-
-
Set dbs = CurrentDb
-
-
DoCmd.OpenForm "Current_Customer_Data", , , "ID = " & Me.lstSearchResults.Column(0)
-
-
End Sub
Here is the code you request for me. It starts when I enter the data needed to be searched for.
Thanks.
NeoPa 32,556
Expert Mod 16PB
Post in the Row Source for your ListBox and we can check it over for you.
If you include the exact (pasted) code for opening the form too we'll check that as well.
The most important thing we need is the Row Source of your ListBox. Without that we can't even start on the rest.
Ok, my green nature is showing here, what is it you mean by row source? I thought u were looking for the code: - lstSearchResults.RowSource = "Value List"
I'm sorry about that.
You have to set RowSourceType to Value List not RowSource.
NeoPa 32,556
Expert Mod 16PB
Ok, my green nature is showing here, what is it you mean by row source? I thought u were looking for the code: - lstSearchResults.RowSource = "Value List"
I'm sorry about that.
Not a problem :)
Just go to the form in Design View and copy the value in the Row Source property of your control (probably lstSearchResults).
That is, unless you set it somewhere in the code, and we're talking after it's been changed. In that case, the whole procedure it's changed in may prove useful.
Ok, so if I preformed the task correctly the Row Source is: Customer ID;First Name;Last Name;Distributor. This is because the top row of my list box acts as a header for the list box.
Thanks
NeoPa 32,556
Expert Mod 16PB
But, surely, that would leave you with just a header line and no data lines :confused:
You are right to be puzzled, but you are indeed correct. When I open the Form, which main function is to search for clients, The list box only has the header. I then input a first name and last name into there respective boxes and click a "Find Caller" button. This button runs a query to search th db for a match, then lists matches. The user will then select the proper person they are looking for.
Does this help your understanding any better? Please let me know, this forum has been really helpful.
Thanks
NeoPa 32,556
Expert Mod 16PB
It certainly does :)
If you take another quick look at post #10 though, you'll see the last paragraph anticipates this scenario, and asks for the code that populates the control if it is done dynamically.
As this is the case, I need that from you now (The code of the (whole) procedure that sets up the RowSource of the control).
If you can do that for me I'm sure we can make some further progress.
Ok, here is the code that defines my db and rs as well as the list box. - Dim dbs As DAO.Database
-
Dim rs As Recordset
-
Dim rs2 As Recordset
-
Dim rs3 As Recordset
-
-
Dim qdf As DAO.QueryDef
-
Dim strSQL As String
-
-
-
Set dbs = CurrentDb
-
-
lblerror1.Visible = False
-
lblError2.Visible = False
-
-
-
If ((FirstName <> "") And (LastName <> "")) Then
-
Set rs = dbs.OpenRecordset("Select * FROM Caller WHERE C_F_Name like '" & FirstName & "*' and C_L_Name like '" & LastName & "*'")
-
End If
-
-
If (((FirstName = "") And (LastName = "")) Or ((FirstName = "") And (LastName <> "")) Or ((FirstName <> "") And (LastName = ""))) Then
-
lblerror1.Visible = True
-
lblError2.Visible = False
-
Else
-
If (rs.EOF) Then
-
lblerror1.Visible = False
-
lblError2.Visible = True
-
Call_ID = ""
-
Telephone = ""
-
Email = ""
-
Dist_ID = ""
-
'lstSearchResults.RemoveItem (1)
-
check1 = False
-
-
Else
-
lblerror1.Visible = False
-
lblError2.Visible = False
-
-
lstSearchResults.RowSource = "Value List"
-
lstSearchResults.ColumnCount = 4
-
lstSearchResults.RowSource = "Customer ID; First Name; Last Name; Distributor"
-
-
While (Not rs.EOF)
-
Dim row As String
-
row = rs(0) & ";" & rs(1) & ";" & rs(2) & ";" & rs(5)
-
lstSearchResults.AddItem (row)
-
rs.MoveNext
-
Wend
-
End If
-
End If
It is very similar to my post, I think it was #4. I hope this helps.
I know I am busting in here but I think you need to look at the following line and make sure the "ID = " is named the same as the field in the database, from the appearance of things it might be [Customer ID]
DoCmd.OpenForm "Current_Customer_Data", , , "[Customer ID]
= " & Me.lstSearchResults.Column(0)
See where I am going this might just resolve your issue.
NeoPa 32,556
Expert Mod 16PB
If that doesn't solve your problem (It probably will), look at the data type of the [whatever ID] field. If it is not numeric then we'll need to look again.
A further couple of points which you can use or ignore... - Row Source Type (As Rabbit said earlier) should replace Row Source in your code that sets it to 'Value List'.
- You should maybe consider using a Table/Query type anyway.
There is an option to show 'Column Heads' and it would mean you could lose a whole chunk of clumsy code.
Just some thoughts.
Thank you both, it works!! I really appreciate it. I don't doubt this will be the last post, but once again thank you.
NeoPa 32,556
Expert Mod 16PB
No problem. Pleased to be of use :)
Glad to know your good to go... :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: james.dixon |
last post by:
Hi
I was wondering if anyone else had had this problem before (can't find
anything on the web about it).
I have three select elements (list boxes - from here on I'll refer to
them as 'the...
|
by: Doslil |
last post by:
I have a form which has a subform.In the main form I have only one
field (this is a drop down list and has a query attached to it) which
selects empno,Name from the EmployeeInformation table.
...
|
by: Sami |
last post by:
I hope someone will tell me how to do this without having to do any VB
as I know nothing in that area. I am a rank beginner in using Access.
I have created a database consisting of student...
|
by: Dave |
last post by:
Hi all,
Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.
What I want to do is to display a list of data in a
datagrid (which I have...
|
by: Mike Wilson |
last post by:
Dear Group,
I have a heirarchical set of database tables, say - "order" and "order_type"
and want to display a series of orders in a grid control, and in place of
the order_type foreign key...
|
by: rickou812 |
last post by:
What I am attempting to do is create a form field in which a company name can be selecting from a drop down box. When selecting I want to display the information from my database about the selected...
|
by: Chittaranjan |
last post by:
Hi All,
I have a problem and hope I can get the better solution from here.
I have a form written in HTML and I need to write that in perl so the main problem I am facing is that I need to...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
Greetings,
I have to load 30,000 unique names into a combox. Filling a dataTable takes
only a few milliseconds. But populating the combobox and displaying the list
takes several seconds - way...
|
by: yogeshtiwarijbp |
last post by:
when i select data from the drop down list box and display data in the datagrid
the first data in the dropdownlistbox not shown the requireddata in the grid. i have used 2 tables and after selecting...
|
by: darrel |
last post by:
I have a DDL list along these lines:
item value="1" text="a"
item value="2" text="b"
item value="3" text="c"
item value="2" text="d"
item value="2" text="e"
item value="1" text="f"
item...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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,...
|
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...
|
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...
| |