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

manissinha

New Member
Joined
Jul 7, 2017
Messages
9
ZmTm8le
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
ZmTm8le




please help

Regards
Manish
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
my code is : searchstring = "SELECT * FROM Table1 WHERE [Name] = '" & TextBox1.Value & "'"

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

<tbody>
[TH="bgcolor: #c0c0c0"] ID [/TH]
[TH="bgcolor: #c0c0c0"] Name [/TH]
[TH="bgcolor: #c0c0c0"] Year [/TH]
[TH="bgcolor: #c0c0c0"] Address [/TH]

</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
 
Upvote 0
Use a query to sort the data in the order you require and select from that.
 
Last edited:
Upvote 0
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 & "'"
 
Upvote 0
Tried with below code but not working

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

[TABLE="class: cms_table"]
<tbody>[TR]
[TH="align: center"]ID[/TH]
[TH="align: center"]Name[/TH]
[TH="align: center"]Year[/TH]
[TH="align: center"]Address[/TH]
[/TR]
[TR]
[TD]1[/TD]
[TD]James[/TD]
[TD]2017[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Mike[/TD]
[TD]2016[/TD]
[TD]123[/TD]
[/TR]
[TR]
[TD] 3[/TD]
[TD]Mike[/TD]
[TD]2017[/TD]
[TD]456[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]James[/TD]
[TD]2018[/TD]
[TD]789[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]James[/TD]
[TD]2019[/TD]
[TD]000[/TD]
[/TR]
</tbody>[/TABLE]


for Mike require below output [TABLE="class: cms_table"]
<tbody>[TR]
[TD]3[/TD]
[TD]Mike[/TD]
[TD]2017[/TD]
[TD]456[/TD]
[/TR]
</tbody>[/TABLE]


for james require below output in userform text boxes

5 James 2019 000



 
Last edited:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top