I need to pull the first 100 records from a database table in Access using VB. I know this is simple, but for some reason it is giving me fits.
Any suggestions?
Thanks!
Printable View
I need to pull the first 100 records from a database table in Access using VB. I know this is simple, but for some reason it is giving me fits.
Any suggestions?
Thanks!
You might want to try opening the table using dbOpenTable instead of dbOpenSnapShot. Sometimes SnapShot gives me a recordcount of 1, when there are over 10,000 records. :(
Set db1 = dBEngine.Workspaces(0).OpenDatabase("W:\DB\info.mdb")
Set table_proj = db1.OpenRecordset("proj", dbOpenTable)
Thanks for the help, but I don't think I was clear enough (my fault).
I don't need a count, I need to pull the first 100 records from the database table, and export them to a text file.
Can you help?
Thanks!
You can use for example
Data1.Recordsource = " SELECT TOP 100 WHERE FirstName = " + "'" + "Rafael" + "'" + " ORDER BY Age "
Set db1 = dBEngine.Workspaces(0).OpenDatabase("W:\DB\info.mdb")
Set table_proj = db1.OpenRecordset("proj", dbOpenTable)
if table_proj.recordcount > 0 then
table_proj.movefirst
for i = 1 to 100
'do your fetching of information here
txtname.txt = table_proj("Name")
next
endif
-=-=-=
Hope the above works :P