473,503 Members | 10,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ordering in Record Set

31 New Member
How does a Record Set order the when there is redundancy?
The example I have is if you search a DB for a customer, but there are two or more customers with the same name, i.e John Smith. I want to show the contact info for each John Smith, but currently I can only get the data to show up for the first John Smith.

Currently I have it setup up like this:
Address1 = rs(3)
Address2 = rs(4)
City = rs(5)
State = rs(6)

You can imagine the rest. With other code I can receive the names for all the names, because I get that many records, but the contact data is the same. How does the rs work so I can code this?
Jan 26 '07 #1
19 1823
MMcCarthy
14,534 Recognized Expert Moderator MVP
You will have to post the actual code you are using. I'm afraid I can't follow what's happening from what you've posted so far. I know that it probably makes sense to you but there is not enough information there for anyone to understand what you are doing or what is going wrong.

Mary
Jan 27 '07 #2
NeoPa
32,557 Recognized Expert Moderator MVP
Like Mary, I can't really follow your explanation.
However, I'll guess that you want to return all records in your recordset where they match your selected name.
In this case (as you haven't supplied any information for this) I'm assuming you have the selection in a TextBox called txtName on your form (we'll call frmCust for clarity). I've also assumed your data is found in the table tblCust.
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * " & _
  2.          "FROM tblCust " & _
  3.          "WHERE CustName='" & Me!txtName & "'"
If this doesn't help, consider checking POSTING GUIDELINES: Please read carefully before posting to a forum for help on how to post a question that's more likely to be understood and get responses.
Good luck.
Jan 27 '07 #3
UAlbanyMBA
31 New Member
I very sorry for not posting all the code. So once again, my question is, if I have two John Smiths, how does the Record Set order the data. Right now it only changes the DistID, and nothing else. How do I fix this. Here you go.

Expand|Select|Wrap|Line Numbers
  1. Private Sub FindCustomer_Click()
  2. Dim FirstName As String
  3.     txtFirstName.SetFocus
  4.     FirstName = txtFirstName.Text
  5.  
  6.     Dim LastName As String
  7.     txtLastName.SetFocus
  8.     LastName = txtLastName.Text
  9.  
  10.     Dim CallID As String
  11.     Call_ID.SetFocus
  12.     CallID = Call_ID.Text
  13.  
  14.     Dim Phone As String
  15.     Telephone.SetFocus
  16.     Phone = Telephone.Text
  17.  
  18.     Dim Email1 As String
  19.     Email.SetFocus
  20.     Email1 = Email.Text
  21.  
  22.     Dim DistID As String
  23.     Dist_ID.SetFocus
  24.     DistID = Dist_ID.Text
  25.  
  26.     Dim dbs As DAO.Database
  27.     Dim rs As Recordset
  28.     Dim rs2 As Recordset
  29.  
  30.     Dim qdf As DAO.QueryDef
  31.     Dim strSQL As String
  32.  
  33.     Set dbs = CurrentDb
  34.  
  35.     lblerror1.Visible = False
  36.     lblError2.Vertical = False
  37.  
  38.     If ((FirstName <> "") And (LastName <> "")) Then
  39.          Set rs = dbs.OpenRecordset("Select * FROM Caller WHERE C_F_Name like '" & FirstName & "*' and C_L_Name like '" & LastName & "*'")
  40.     End If
  41.  
  42.     If (((FirstName = "") And (LastName = "")) Or ((FirstName = "") And (LastName <> "")) Or ((FirstName <> "") And (LastName = ""))) Then
  43.         lblerror1.Visible = True
  44.         lblError2.Visible = False
  45.     Else
  46.         If (rs.EOF) Then
  47.             lblerror1.Visible = False
  48.             lblError2.Visible = True
  49.             Call_ID = ""
  50.             Telephone = ""
  51.             Email = ""
  52.             Dist_ID = ""
  53.             lstSearchResults.RemoveItem (1)
  54.  
  55.         Else
  56.             lblerror1.Visible = False
  57.             lblError2.Visible = False
  58.             Call_ID = rs(0)
  59.             Telephone = rs(3)
  60.             Email = rs(4)
  61.             Dist_ID = rs(5)
  62.  
  63.             Set rs2 = dbs.OpenRecordset("SELECT Date_filed, Customer_Order_Number, Purchase_Order_Number FROM Request WHERE Request.Call_ID = Call_ID")
  64.  
  65.             lstSearchResults.RowSource = "Value List"
  66.             lstSearchResults.ColumnCount = 3
  67.             lstSearchResults.RowSource = "Date Filed; Customer Order Number; Purchase Order Number"
  68.             While (Not rs2.EOF)
  69.                Dim row As String
  70.                 row = rs2(0) & ";" & rs2(1) & ";" & rs2(2)
  71.                 lstSearchResults.AddItem (row)
  72.                 rs2.MoveNext
  73.             Wend
  74.         End If
  75.     End If
  76.  
  77. End Sub
  78.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstSearchResults_Click()
  2.     Dim dbs As DAO.Database
  3.     Dim qdf As DAO.QueryDef
  4.  
  5.     Set dbs = CurrentDb
  6.  
  7.     Dim strSQL As String
  8.     strSQL = "Select * FROM Request WHERE Customer_Order_Number = " & lstSearchResults.ItemData(1)
  9.     Set qdf = dbs.CreateQueryDef("GetRequest", strSQL)
  10.  
  11.     DoCmd.OpenForm ("Request3")
  12. End Sub
  13.  
Feb 2 '07 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
You never actually search the recordset using a loop. It's not that it's not returning more than one record you're just not looping through them. Have a look at this example in the tutorials section.

Mary
Feb 2 '07 #5
UAlbanyMBA
31 New Member
That tutorial really helps. I am just not sure what "Query2" is supposed to do? That may sound really stupid, but that is tripping me up.
Feb 2 '07 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
That tutorial really helps. I am just not sure what "Query2" is supposed to do? That may sound really stupid, but that is tripping me up.
In the example the code loops through query1 and for each record it loops through query2 to see if it can find a matching value. If a matching value is found it preforms the update if not it continues to loop. When the code finished looping through query2 it moves on to the next record in query1 and starts again.

Mary
Feb 2 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Implement as much as you can using the example and then we can address any outstanding problems.

Mary
Feb 2 '07 #8
UAlbanyMBA
31 New Member
That wasn't quite what I meant by what is query2.

My Query1 =
Expand|Select|Wrap|Line Numbers
  1. "Select * " & _
  2. "FROM Caller " & _
  3. "WHERE C_F_Name like '" & FirstName & "*' " & _
  4.   "AND C_L_Name like '" & LastName & "*'"
So that gives me my rs of all the "John Doe's" in my system.

Now what is Query2, and how is that gonna help me differentiate between John Doe #3 and John Doe #7?

I have no other search parameters. All I am trying to get out of this is for my form to show the appropriate information for each John Doe. I think that is what these nested loops are doing, but like I said, I don't have a Query2.

I hope this helps clarify my problem, if not I am sorry.
Feb 8 '07 #9
NeoPa
32,557 Recognized Expert Moderator MVP
That wasn't quite what I meant by what is query2.
I assume you meant - How does Query2 fit into my situation?
You probably don't have a need for a 'Query2' in your situation.
The tutorial illustrates how multiple queries can be processed together within VBA code. It includes examples of a number of the functions you need to use when doing something similar. The tutorial probably has more than you need, you just need to ignore the bits that you don't need.
Does that help to clarify?
Feb 8 '07 #10
UAlbanyMBA
31 New Member
Kind of. But if I may not need a second query, why would I need to do this loop? Also, if I don't need this second query or the loop, that puts me back to my original question. How does a rs organize its data?

If I have a table with 5 columns, and 3 like names (i.e. John Doe)
Is John Doe #1 represented by rs(0) - rs(4)
John Doe #2 rs(5) - rs(9)
John Doe #3 rs(10) - rs(14)?

Thanks
Feb 8 '07 #11
NeoPa
32,557 Recognized Expert Moderator MVP
You're losing me a bit here.
However, that's certainly not how it works. The tutorial (ignoring Query2) should illustrate how this works, but briefly :
Each separate record (or row if you prefer) is a different line of data. A recordset object can refer to only one record at a time. Normally (although there are often multiple ways of doing things), a field in the current record of a recordset (rs) is referred to as rs!FieldName.
Is that an easier way to think of it?
Feb 8 '07 #12
UAlbanyMBA
31 New Member
So using this example:

FName LName ID
John Doe 12
John Doe 35
John Doe 98

I have a record set with three records. So if I were to assign values to the rs, i would only only have rs(0), rs(1), & rs(2)? Or would those numbers only represent the first record?

Here is where I am also confused. When I code rs!FieldName, is FieldName as reserved word in this case or do I insert my specific FieldName in this case?

Now to address my original question, which may help clarify the problem for both of us. In my form I have three textboxes. One for FName, LName, and ID. I have a find button for the record. I type in FName and LName, and click find. The boxes will fill with John Doe 12, but when I click the next record on the bottom of the form, nothing changes. My code from a previous post shows this.

I hope this helps some more.

Thank you.
Feb 9 '07 #13
UAlbanyMBA
31 New Member
Just noticed something in the tutorial, that doesn't work for my case.

The if statement

If rs![FieldName] = rs2!FieldName Then
'rs2.Edit
'rs2![FieldName] = 'Your Value'
'rs2.Update
End If

Since I don't have 2 query, which would make 2 rs, what do I compare?
Feb 9 '07 #14
MMcCarthy
14,534 Recognized Expert Moderator MVP
The problem is what you are trying to do with this code. The initial point of how to get more than one result from a recordset has been answered. The bigger question here is why are you using recordsets and what exactly are you trying to do with the results.

Mary
Feb 9 '07 #15
UAlbanyMBA
31 New Member
Ok, I hope this explains what I am doing better.

I have a database filled with clients. When a customer calls the user first must see if the customer exists in the system. This requires the first and last name each in its own respective textbox. The find button first makes sure both fields have data in them, and then creates a record set of all the the fields for any name matching the search criteria. In this case John Doe, where fictionally have three of them. After the find button is clicked the empty textboxes on the form are filled with the information from that particular record. In my past examples this would be John Doe's ID number. What I want is for every time I click the next record button on the bottom, I want the ID number to change, showing it changes the record set.

My real world example of course has more than just ID, but several other fields.

Thank you.
Feb 9 '07 #16
MMcCarthy
14,534 Recognized Expert Moderator MVP
Ok, I hope this explains what I am doing better.

I have a database filled with clients. When a customer calls the user first must see if the customer exists in the system. This requires the first and last name each in its own respective textbox. The find button first makes sure both fields have data in them, and then creates a record set of all the the fields for any name matching the search criteria. In this case John Doe, where fictionally have three of them. After the find button is clicked the empty textboxes on the form are filled with the information from that particular record. In my past examples this would be John Doe's ID number. What I want is for every time I click the next record button on the bottom, I want the ID number to change, showing it changes the record set.

My real world example of course has more than just ID, but several other fields.

Thank you.
Ok, there are better approaches to searching for records in a form. Have a look at NeoPa's tutorial on this and then come back with any questions.

Example Filtering on a Form

Mary
Feb 9 '07 #17
NeoPa
32,557 Recognized Expert Moderator MVP
Sorry I couldn't get back to this earlier.
This is to answer your specific questions and doesn't negate or contradict any other comments posted since.
I have a record set with three records. So if I were to assign values to the rs, i would only only have rs(0), rs(1), & rs(2)? Or would those numbers only represent the first record?
Absolutely, when the first record is the current record.
Whenever the current record pointer is moved, these references move with it.
It is not possible to access multiple records of a recordset at the same time in code.
Here is where I am also confused. When I code rs!FieldName, is FieldName as reserved word in this case or do I insert my specific FieldName in this case?
You need to replace the word (FieldName) with the actual name of your own field.
Feb 9 '07 #18
NeoPa
32,557 Recognized Expert Moderator MVP
Just noticed something in the tutorial, that doesn't work for my case.

The if statement

If rs![FieldName] = rs2!FieldName Then
'rs2.Edit
'rs2![FieldName] = 'Your Value'
'rs2.Update
End If

Since I don't have 2 query, which would make 2 rs, what do I compare?
This indicates to me that you are trying to duplicate the tutorial as an answer to your problem. This is not the right idea at all. You need to learn the concepts from the tutorial and fit them into your own situation. In the tutorial are examples in code of,
  • Moving the current record.
  • Accessing data within the current record.
  • Looping around your code to process all records in a recordset.
  • Etc.
Feb 9 '07 #19
NeoPa
32,557 Recognized Expert Moderator MVP
Don't forget to check out the tutorial in Post #17 (That may have scrolled off the page now). You can even download the example database there and look at it in more detail. I feel most of what you need is in there. Come back and let us know how you get on. We'll still be here when you've done that.
Feb 9 '07 #20

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

Similar topics

2
587
by: Ken Fine | last post by:
(originally posted to one of macromedia's groups; no help, so hopefully someone here can help me out. I'm using VBScript ASP.) When designing administrative interfaces to websites, we often need...
5
8874
by: Marnie Parker | last post by:
I am adding a drop down comb box to an existing database I wrote about a year ago. This combo box list names where the user can select which record to go to. Sigh. Last, First Name and a...
3
1403
by: Richard Setford | last post by:
Hi there, Bit of an Access newbie here in need of some help. First time in here so please be gentle with me. Here's what I'm trying to achieve. I want to build a database which records the...
4
1531
by: Chris | last post by:
Any good routines or suggestions to assist me in re-ordering my records in my datagrid? i.e. I have a field in each record that is used for ordering (i.e. 1,2,3,4). I would like to implement a...
6
1547
by: James Pharaoh | last post by:
Hi, I'm trying to work out how to make sure things are read from a table in a consistent order. The table represents a queue of items and also the history of those items. Even with...
33
3362
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a...
8
1679
by: DrewKull | last post by:
Hello, I have a query which sums check boxes (so 0 or -1) then Abs the sum so i can get the number of check box 'checked' per column... based on start and end date. SELECT Abs(Sum(CommCon)) AS ,...
4
3717
by: Andrevv | last post by:
Hi all! Im totaly new in programing, so i need some help if someone can help me... Im programing in VS 2005, C# language and using MS SQL Server 2005 . So, after i fill my table with 10 records,...
4
2070
ChrisWang
by: ChrisWang | last post by:
Dear all, I am reading the book "Core Python Programming". In the chapter talking about modules, it says the modules should follow this ordering: import Python Standard Library modules ...
15
2258
ajhayes
by: ajhayes | last post by:
I posted a question here last week about an ordering database I'm trying to set up, and got some excellent help. So I'm hoping some of you might be able to get me on the right track with another...
0
7361
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
7015
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
7470
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
5026
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
4693
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...
0
3183
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
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
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...

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.