
Function to return data contained in a table
You are on the right path with a read only, but do not use a snapshot. Use
the seek method on a table, however use the Read Only constant.
Function Foo (lngId as long) as string
dim db as database, rst as recordset
set db=currentdb
set rst=db.openrecordset("tblCustomer",dbReadOnly)
rst.index = "PrimaryKey"
rst.seek "=", lngID
Foo=rst!CustomerName
End Function
That should do the trick.
(This is for Access 95/97) Let me know if you are using Access 2.
--
Stephen Forte
President, NYC Access VB User Group
http://www.auroradev.com/
I am trying to write a function to return the customer name from the
customer table. I am passing the customer key to the function contained in
the module, and would like to return the customer name. Since this will be
used many times in my program, I think it is best to create a snapshot in
read only mode and open the table once when the screen is open, and close
it only after several records are entered.
I would appreciate any help someone could provide. Thank you very much!
--
Please respond directly to my Email account at the following address:
Thank you in advance!
John
----------