473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to Get Particular Records from ACCESS

Hello my database looks like

Name Age
Hello 21
Hi 25
Bye 27
Welcome 16
Say 19
XYZ 18

Now i want to Retrive All the record between Column 3 to column 6 How i can do that In Microsoft Access .Here Condition is I can't Add any new column to The database
Apr 22 '08 #1
19 1752
mshmyob
904 Expert 512MB
Hello Rupechamp,

I only see 2 columns (Name & Age)

Answer your 2nd question you go into design mode in your table and add more columns.

cheers,

Hello my database looks like

Name Age
Hello 21
Hi 25
Bye 27
Welcome 16
Say 19
XYZ 18

Now i want to Retrive All the record between Column 3 to column 6 How i can do that In Microsoft Access .Here Condition is I can't Add any new column to The database
Apr 22 '08 #2
Big X
42
Hello my database looks like

Name Age
Hello 21
Hi 25
Bye 27
Welcome 16
Say 19
XYZ 18

Now i want to Retrive All the record between Column 3 to column 6 How i can do that In Microsoft Access .Here Condition is I can't Add any new column to The database
You will have to create a query. You have only listed two column names. If you supply us the column names you want and the table name, I can write you a sql statement that can retrieve the information you want.

You question isnt to precise either. Do you want all information in column 3 to 6(all records). Or do you want all the information from rows 3 to 6 .
Apr 23 '08 #3
Hello All,
new column means i don't want to add any new column in my database like column no etc. On the basis on these two column only i want to write a query which will get all the data between column 3 and 6 in microsoft Access that's all i have to Do.And i think it will same even we want to try for ll rows value ,instead of Field name we can use * but how to access particular row 3 ,4,5,6 etc

Thanx
Apr 23 '08 #4
mshmyob
904 Expert 512MB
You cannot write a Query to get the data for column 3 to 6 if you do not have a column 3 to 6.

If what you really want is a query to get the data for rows 3 to 6 then you need to tell us what the query is based on (ie: Peoples names - Names that start with A to C for example, or people whose age falls into a certain range)

Give us some idea of what you want to filter on.

cheers,

Hello All,
new column means i don't want to add any new column in my database like column no etc. On the basis on these two column only i want to write a query which will get all the data between column 3 and 6 in microsoft Access that's all i have to Do.And i think it will same even we want to try for ll rows value ,instead of Field name we can use * but how to access particular row 3 ,4,5,6 etc

Thanx
Apr 23 '08 #5
You cannot write a Query to get the data for column 3 to 6 if you do not have a column 3 to 6.

If what you really want is a query to get the data for rows 3 to 6 then you need to tell us what the query is based on (ie: Peoples names - Names that start with A to C for example, or people whose age falls into a certain range)

Give us some idea of what you want to filter on.

cheers,
My fault I am Sorry ,I mean to say from row 3 to row 6.There is Name which is Not alphabeticaly and age also not in any paricular order just want to get the value on the basis of row only

Thanx
Apr 23 '08 #6
mshmyob
904 Expert 512MB
It is very important to understand that Access does NOT use record numbers. The numbers you see at the bottom of the screen are not true record numbers but just pointers based on the sort order of the view you are currently on. If you change the sort order your so called record numbers (row numbers) will change.

The key point you must remember when using the code is that you MUST ALWAYS open the table in the EXACT same sort order all the time. Since ACCESS does not use record numbers if you open the table with a different sort order you will get different results.


The following code will show you how to extract data based on 'record numbers'. I am showing a single record (#3). You can create a loop to extract data up to whatever 'record number' you want. I am displaying the result to the form.

Assume the form is bound to your table and you have 2 text boxes called txtName and txtAge and a command button. Put the following code in the On Click event of the command button.

The 2 fields (columns) in your table are called fldName and fldAge

Expand|Select|Wrap|Line Numbers
  1. Dim rs As Recordset
  2. ' create a recordset
  3. Set rs = Me.RecordsetClone
  4. ' populate the recordset - you must do this
  5.     rs.MoveLast
  6.     rs.MoveFirst
  7. ' end populating recordset
  8.  
  9. ' move to the 3rd 'record number' (remember absolute position is 0 based
  10.     rs.AbsolutePosition = 2
  11. ' create your loop here for more results
  12.     Me.txtName = rs!fldName
  13.     Me.txtAge = rs!fldAge
  14.  

cheers,

My fault I am Sorry ,I mean to say from row 3 to row 6.There is Name which is Not alphabeticaly and age also not in any paricular order just want to get the value on the basis of row only

Thanx
Apr 23 '08 #7
Big X
42
Couldn't he just added a column with auto number ' RecordNum' then run a query.

Expand|Select|Wrap|Line Numbers
  1. Select *
  2. From ['TABLENAME']
  3. Where RecordNum IN(3,4,5,6) ;
  4.  
Apr 24 '08 #8
mshmyob
904 Expert 512MB
Sounds good in theory but what happens when he starts deleteing records and the autonumbers start having gaps or he has a different sort, then the Access 'record numbers' won't match the RecordNum values you have in your table.

Note I put quotes around 'record number' since Access doesn't use record numbers and trying to use record numbers for anything in Access is frowned upon and is not reliable.

I don't know the OP's reason for wanting to do what he is asking but we have very limited information from him and I am trying to give him what he is asking for (regardless if I agree with it).

cheers,

Couldn't he just added a column with auto number ' RecordNum' then run a query.

Expand|Select|Wrap|Line Numbers
  1. Select *
  2. From ['TABLENAME']
  3. Where RecordNum IN(3,4,5,6) ;
  4.  
Apr 24 '08 #9
Sounds good in theory but what happens when he starts deleteing records and the autonumbers start having gaps or he has a different sort, then the Access 'record numbers' won't match the RecordNum values you have in your table.

Note I put quotes around 'record number' since Access doesn't use record numbers and trying to use record numbers for anything in Access is frowned upon and is not reliable.

I don't know the OP's reason for wanting to do what he is asking but we have very limited information from him and I am trying to give him what he is asking for (regardless if I agree with it).

cheers,

Thanx , I know That i can Do it With The help of record Set But Don't want it to do at code level had already used this record no logic .Right Now my requirement is that can i do it itself a query Level. I can tell one thing .I had triwd where Not In clause it Works but it fails if i have duplicate value inside my database

Thanx
Apr 24 '08 #10
mshmyob
904 Expert 512MB
What is your primarky key and post your SQL for your query.

cheers,

Thanx , I know That i can Do it With The help of record Set But Don't want it to do at code level had already used this record no logic .Right Now my requirement is that can i do it itself a query Level. I can tell one thing .I had triwd where Not In clause it Works but it fails if i have duplicate value inside my database

Thanx
Apr 24 '08 #11
What is your primarky key and post your SQL for your query.

cheers,
Here is the query

SELECT TOP 3 * FROM Table001 WHERE Name not in (select distinct Name from (SELECT TOP 3 * FROM (SELECT * FROM Table001 )));

It Shows The Row value from 3 to 6 But it remove duplicate data due to Where clause . And in this there is no Primary key .it's Simply two Line table.And one more hing it's in Access not in SQL

Thanx
Apr 24 '08 #12
mshmyob
904 Expert 512MB
You can get it to work if you add another Column (make it an Autonumber) like Big X says and make it the PK and then change the field 'Name' in your query to the autonumber column and it will display even if Name is duplicated.

Note: Your ordering of the data will still give you different results if you change it.

The biggest problem you are having is that you have an improperly designed table.

cheers,

Here is the query

SELECT TOP 3 * FROM Table001 WHERE Name not in (select distinct Name from (SELECT TOP 3 * FROM (SELECT * FROM Table001 )));

It Shows The Row value from 3 to 6 But it remove duplicate data due to Where clause . And in this there is no Primary key .it's Simply two Line table.And one more hing it's in Access not in SQL

Thanx
Apr 24 '08 #13
You can get it to work if you add another Column (make it an Autonumber) like Big X says and make it the PK and then change the field 'Name' in your query to the autonumber column and it will display even if Name is duplicated.

Note: Your ordering of the data will still give you different results if you change it.

The biggest problem you are having is that you have an improperly designed table.

cheers,
Thanx for your Suggestion .So i can Assume that There is no Direct Solution in case of Access Even if i use AutoNumber Column and Deleted Some Rows from Middle of table Then Again Problem .Thanx for all your Suggestion and to Confirm my point . Yes i agrees that it's a bad designed table .But in this Senario i am helpless I can't do anything in this case have to Do everything By these column only .

Thanx
Apr 24 '08 #14
NeoPa
32,556 Expert Mod 16PB
The following SQL may work for you with the previous provisos :
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 4 *
  2. FROM Table001
  3. WHERE [Name] Not In(
  4.     SELECT TOP 2 [Name]
  5.     FROM Table001)
SQL is a language rather than a package. MS Access includes it's own (Jet) SQL engine. Not to be confused with MS SQL Server which is a package (application).

Without further data to work with (IE an AutoNumber field) I cannot see that it's possible to do exactly what you want accurately.

Nice concept use of the sub-query by the way (from your post #12) ;)
Apr 24 '08 #15
The following SQL may work for you with the previous provisos :
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 4 *
  2. FROM Table001
  3. WHERE [Name] Not In(
  4.     SELECT TOP 2 [Name]
  5.     FROM Table001)
SQL is a language rather than a package. MS Access includes it's own (Jet) SQL engine. Not to be confused with MS SQL Server which is a package (application).

Without further data to work with (IE an AutoNumber field) I cannot see that it's possible to do exactly what you want accurately.

Nice concept use of the sub-query by the way (from your post #12) ;)
Thanx Neo Pal,
I had tried this Also Assume a Condition When i have Only one name in All the Rows Then this Also fails.Here is my Query
Expand|Select|Wrap|Line Numbers
  1. SELECT Top 3 Name from Table001 Where Name NOT IN(Select Top 3 Name from Table001) UNION SELECT NAME FROM (SELECT NAME,COUNT(*) FROM Table001 GROUP BY NAME HAVING COUNT(*) >1)
And
Expand|Select|Wrap|Line Numbers
  1. select name from (select top 3 * from Table001 where name not in (select top 3 name from Table001) and name in (select top 6 name from Table001) ) union SELECT NAME FROM (SELECT NAME,COUNT(*) FROM Table001 GROUP BY NAME HAVING COUNT(*) >1) where name in (select top 6 name from Table001)
By Doing all of this Now i Observed That Apart from RecordSet there is no way to fetch the data between two rows .Means have to write Some code too.

Thanx
Apr 24 '08 #16
FishVal
2,653 Expert 2GB
Hi, all.

Actually there is a somewhat ugly workaround using VBA function with static variable incrementing on call and able to be reset at certain conditions. UNION query is used to reset the variable.

Expand|Select|Wrap|Line Numbers
  1. Public Function DynAN(varDummy As Variant, blnReset As Boolean) As Long
  2.  
  3.     Static lngAN As Long
  4.  
  5.     If blnReset Then lngAN = -1
  6.     lngAN = lngAN + 1
  7.     DynAN = lngAN
  8.  
  9. End Function
  10.  
Query: qry1
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, True) AS AN
  2. FROM tbl
  3. UNION SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, False) AS AN
  4. FROM tbl;
  5.  
Query: returns enumerated list
Expand|Select|Wrap|Line Numbers
  1. SELECT qry1.*
  2. FROM qry1
  3. WHERE qry1.AN<>0 And qry1.AN>=3 And qry1.AN<=8
  4. ORDER BY qry1.AN;
  5.  
Attaching sample ...

Ok. Attached.

Regards,
Fish

P.S. For further reference, this solution is a modification of that one adapted for table containing duplicate records.
Attached Files
File Type: zip DynamicEnum.zip (15.4 KB, 58 views)
Apr 24 '08 #17
NeoPa
32,556 Expert Mod 16PB
That's what the "previous provisos" were all about.

In your scenario with the necessary fields simply not there you can approximate to a valid solution at best.

The GIGO law says you won't get much better out of it I'm afraid.
Apr 24 '08 #18
mshmyob
904 Expert 512MB
Nice Fish... Just changed the criteria in qryEnumeratedList to get to row 6.

cheers,

Hi, all.

Actually there is a somewhat ugly workaround using VBA function with static variable incrementing on call and able to be reset at certain conditions. UNION query is used to reset the variable.

Expand|Select|Wrap|Line Numbers
  1. Public Function DynAN(varDummy As Variant, blnReset As Boolean) As Long
  2.  
  3.     Static lngAN As Long
  4.  
  5.     If blnReset Then lngAN = -1
  6.     lngAN = lngAN + 1
  7.     DynAN = lngAN
  8.  
  9. End Function
  10.  
Query: qry1
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, True) AS AN
  2. FROM tbl
  3. UNION SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, False) AS AN
  4. FROM tbl;
  5.  
Query: returns enumerated list
Expand|Select|Wrap|Line Numbers
  1. SELECT qry1.*
  2. FROM qry1
  3. WHERE qry1.AN<>0 And qry1.AN>=3 And qry1.AN<=8
  4. ORDER BY qry1.AN;
  5.  
Attaching sample ...

Ok. Attached.

Regards,
Fish

P.S. For further reference, this solution is a modification of that one adapted for table containing duplicate records.
Apr 24 '08 #19
Thanx FishVal for your efforts .I really Appreciate That you all guy had spended your time for me. Anyway I checked your Query and it's Not Working Here . As i already mention that i am able to do this with the help of recordset but with query i don't know Because i don't have much idea on access.Here is my Sample Table on Which i had Checked your query on the basis of name

Name Description Value
Rupesh Hello 23
Ajay Hi 45
Rupesh Yes 60
Rupesh Okay 78
Rupesh Hello 23
Rupesh Hi 45
cc Yes 60

Thanx

Hi, all.

Actually there is a somewhat ugly workaround using VBA function with static variable incrementing on call and able to be reset at certain conditions. UNION query is used to reset the variable.

Expand|Select|Wrap|Line Numbers
  1. Public Function DynAN(varDummy As Variant, blnReset As Boolean) As Long
  2.  
  3.     Static lngAN As Long
  4.  
  5.     If blnReset Then lngAN = -1
  6.     lngAN = lngAN + 1
  7.     DynAN = lngAN
  8.  
  9. End Function
  10.  
Query: qry1
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, True) AS AN
  2. FROM tbl
  3. UNION SELECT tbl.txtName, tbl.lngAge, DynAN(tbl.lngAge, False) AS AN
  4. FROM tbl;
  5.  
Query: returns enumerated list
Expand|Select|Wrap|Line Numbers
  1. SELECT qry1.*
  2. FROM qry1
  3. WHERE qry1.AN<>0 And qry1.AN>=3 And qry1.AN<=8
  4. ORDER BY qry1.AN;
  5.  
Attaching sample ...

Ok. Attached.

Regards,
Fish

P.S. For further reference, this solution is a modification of that one adapted for table containing duplicate records.
Apr 25 '08 #20

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

Similar topics

1
by: Steve Claflin | last post by:
I have a database with a moderate number of records in several tables (the biggest table at the moment is about 800 records). In development it got moved between 2K and XP repeatedly. Several...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
5
by: Grant | last post by:
Hi Is there a way to recover deleted records from a table. A mass deletion has occurred and Access has been closed since it happened Louis
6
by: Damon Grieves | last post by:
Hi I just want to be sure I understand how the Access client works. If I have an Access back end with a million records on a server and an Access client. If the client is installed on the users pc...
1
by: RiesbeckP | last post by:
Hi All, I have a DB where there are customer numbers and a few other fields. I want to be able to pull all of the null records for a particular field as well as all the other customer numbers...
3
by: BrianDP | last post by:
I have a database with a split front end/back end. There is a key table in the back end called Catalog, and it is sort of a central key table for all sorts of things. It's a list of all the jobs...
0
by: Murali | last post by:
In MsAccess project I Create the Link table with Sqlserver 2000. I am facing the multiuser Problem in my application. The problem describes below: If one user is updating one record and at that...
1
by: effiw | last post by:
I'm working with an application that has an MS Access front end linked to the SQL Server DB backend. During a period of one week, 32 records of a spefic event (and all related records to that event)...
5
by: Victor | last post by:
Hello, I have a table which has around 3 billion records on an env and a simple query against it goes for a tablescan eventhough an index has been defined and this happens only on an env. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.