Opening a recordset (1 Viewer)

grenee

Registered User.
Local time
Today, 07:26
Joined
Mar 5, 2012
Messages
210
Good Day All,
Can someone explain why this code results in no records returned when the table has several records. And if the criteria is excluded all the records are returned.

Code:
  Set rst = curDatabase.OpenRecordset("Cash posting Sub Table", "[mainPostingID] =" & 7)]
 

MarkK

bit cruncher
Local time
Today, 07:26
Joined
Mar 17, 2004
Messages
8,181
The DAO.Database.OpenRecordset method takes four parameters, but none of them are the SQL selection criteria. That is meant to be written into the SQL's WHERE clause, maybe something like...
Code:
   Const SQL as string = _
      "SELECT * FROM [Cash posting Sub Table] WHERE mainPostingID = "

   Set rst = CurrentDb.OpenRecordset(SQL & 7)
See what's happening there?
Mark
 

Users who are viewing this thread

Top Bottom