Open Access to a specific record using form or query

  • Thread starter Thread starter Spot
  • Start date Start date
S

Spot

I am trying to setup a little experiment with Microsoft Streets and Access.
The situation I have is this. I have several points mapped in streets.
Each point will have a record associated with it in Access. I know how to
link to the database with the records in it, but I don't know how to open to
the record that applies to the point in question.

Can anyone tell me how to set Access to open to a specific record? I assume
that I would have to define a query and run that somehow but I really only
know the GUI of Access and not the scripting.

Please help
 
Hi,


You can use DBEngine to open the database. DBEngine is an object
automatically initialized for you as soon as you refer to it
(GlobalMultiUse Instance) and that the DAO library is included in your
project.

You can use the DAO database object to then open a DAO recordset. Supply
the SQL statement with the WHERE clause to restrict the records to be
returned.


Dim CurDb As DAO.Database
Set CurDb=DBEngine.OpenDatabase("C:\..........." )

Dim rst As DAO.Recordset
Set rst=CurDb.OpenRecordset("SELECT * FROM myTable WHERE pk=" &
222 )



would open a recordset with the record(s) where pk=222. If the field is
alphanumerical, rather than numerical, use:

Set rst=CurDb.OpenRecordset("SELECT * FROM myTable WHERE city=""" &
strCity & """" )



assuming strCity is a city name without " in it.




Hoping it may help,
Vanderghast, Access MVP
 
Back
Top