Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA queries

Status
Not open for further replies.

sramey00

Programmer
Jun 9, 2004
149
US
I am new to programming access w/ vba and i was wondering if i could get a push in the right direction.

I have a table in my database which i need to retrieve information from. the part i am a stuck at, is how do i access this table (cases)?

I eventually want to take every record from the db and write it to a pdf file (once i have the data, i will use the pdf printer to create the file).

My SQL mentality would be to make a cursor and select everything into that cursor, then record by record, create the pdf. Access doesn't support Cursors, so what could be used as a substitute?

Thanks!



Mr. Steve

 
There are many ways to get your data from tables - this is the way I use, this loops through the table empnames and looks at the employee_firstname and employee_surname fields.



Dim dbs As Database, rst As Recordset, empfirstname As string, empsurname As string
Set dbs = DBEngine.Workspaces(0).Databases(0)
Set rst = dbs.OpenRecordset("SELECT * FROM empnames;")
with rst
do until rst.eof
empfirstname = rst!employee_firstname
empsurname = rst!employee_surname
rst.movenext
'Here would be some code to do something useful with the data
loop
end with
rst.close
dbs.close

Hopefully it'll help you get started. There'll be other ways suggested no doubt.
 
thanks for your help... is there any limit as to how many record sets this can hold? my test database has only about 5 or so records only for testing purposes... the live database will have approx 500 records.



Mr. Steve

 
I've gone quite successfully through several thousand records across several tables. Don't think theres any strict limit - only time really and you can help yourself out by ensuring you've indexed the tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top