Create recordset programatically

G

George Stevenson

I'm using Access2000. I need to be able to work with a subset of records in
my main database of public records from the register of deeds. One of the
indices is by Book/Page. I need to be able to determine what records might
already exist in the database with an existing book/page when a new record
is to be added in my add routine. The existing DB name is GES.

I want to be able to create a small recordset in program code with a select
statement that uses the book/page that is on an incoming transaction. In
the example below, I've hard coded the book page for illustrative purposes.

Here is what I'm trying to do, could someone point the way so that I can
flesh this out more?

Dim myBook As String, myPage As String, rstGESBkPg As Recordset

myBook = "6917"
myPage = "647"
Set db = CurrentDb()
Set rstGESBkPg = New Recordset
rstGESBkPg.Open "Select * From GES where ges.fcdtbook =" & myBook & " and
ges.fcdtpage=" & myPage & "", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
 
C

chris.nebinger

If the fields are text, you need to have single quotes areound the
fields


rstGESBkPg.Open "Select * From GES where ges.fcdtbook ='" & myBook & "'
and
ges.fcdtpage='" & myPage & "'",


That is:

where ges.fcdtbook = [SINGLEQUOTE][DOUBLEQUOTE] & myBook &
[DOUBLEQUOTE][SINGLEQUOTE] and ges.fcdtpage =
[SINGLEQUOTE][DOUBLEQUOTE] & myPage &
[DOUBLEQUOTE][SINGLEQUOTE][DOUBLEQUOTE]

hth,

Chris Nebinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top