ACCESS : Import last saved record of particular Name from access database to excel userform

manissinha

New Member
Joined
Jul 7, 2017
Messages
7
HI

I want to Import last saved record of particular Name from access database to excel userform.

It give me the first record saved for particular name. (FIFO)
I want to import using LIFO method/ code




please help

Regards
Manish
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

manissinha

New Member
Joined
Jul 7, 2017
Messages
7
my code is : searchstring = "SELECT * FROM Table1 WHERE [Name] = '" & TextBox1.Value & "'"

Access database tabel1 :
IDNameYearAddress
1James2017abc
2Mike2016123
3Mike2017456
4James2018789
5James2019000

<tbody>
</tbody>

my code give me first saved "Mike" data year "2016" and address "123"
however i wand last saved "Mike" data , Year "2017" and address "456"

my excel uerform contains Name as Textbox1
Year as Textbox2
Address as Textbox3
search record using Textbox1 by entering name manually
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
779
Use a query to sort the data in the order you require and select from that.
 
Last edited:

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
779
What do you mean how.? :confused:
You just create a query, use the GUI if you are not familiar with sql. The you use *that* as your source. So your select would be

Rich (BB code):
searchstring = "SELECT * FROM MySortedQuery WHERE [Name] = '" & TextBox1.Value & "'"
 

manissinha

New Member
Joined
Jul 7, 2017
Messages
7
Tried with below code but not working

searchstring = "SELECT * FROM Table1 ORDER BY NAME DESC WHERE [Name] = '" & TextBox1.Value & "'"

IDNameYearAddress
1James2017abc
2Mike2016123
3Mike2017456
4James2018789
5James2019000

<tbody>
</tbody>


for Mike require below output
3Mike2017456

<tbody>
</tbody>


for james require below output in userform text boxes

5 James 2019 000



 
Last edited:

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
779
Syntax is SELECT, then WHERE *then* ORDER

I would have thought you would need something along the lines of
Rich (BB code):
"SELECT * FROM Table1  WHERE [Name] = '" & TextBox1.Value & "'"  & " ORDER BY YEAR DESC

to get all the records. If you are just interested in the one record, then perhaps

Rich (BB code):
"SELECT TOP 1 Table1.* FROM Table1  WHERE [Name] = '" & TextBox1.Value & "'"  & " ORDER BY YEAR DESC


Tested via QBE
Rich (BB code):
SELECT TOP 1 Transactions.*, Transactions.Description, Transactions.Date
FROM Transactions
WHERE (((Transactions.Description) Like "*208271"))
ORDER BY Transactions.Date DESC;
HTH
 

Watch MrExcel Video

Forum statistics

Threads
1,096,308
Messages
5,449,588
Members
405,573
Latest member
Diogo Martins

This Week's Hot Topics

Top