require help with vba query

ashiers

New member
Local time
Today, 06:12
Joined
Oct 3, 2008
Messages
8
Hi Guys,

I'm working on a Form in Access 2007. In the vba code window I have the following:

Code:
Private Sub Display_Cost_Centers(SubsectionID As String)

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim query As String
Dim recordCount As Integer

Debug.Print "SubsectionID: " & SubsectionID

query = "SELECT CC_NUMBER FROM COST_CENTER WHERE COST_CENTER.SUBSECTION_ID=" & SubsectionID & ";"
Debug.Print query
'On Error GoTo ErrHandler

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(query, dbOpenSnapshot)

recordCount = rst.recordCount
Debug.Print "RecordCount: " & recordCount

...

END SUB
Please note the query: SELECT CC_NUMBER FROM COST_CENTER WHERE COST_CENTER.SUBSECTION_ID=" & SubsectionID & ";"

As you can see, it is quite a simple statement.
When I create an actual query in Access and use the value one "1" for the SubsectionID, I get the appropriate return of two records from the COST_CENTER table. However, when I run the code above containing the same SQL statement, I get only a return of one record.

Am I missing something? Any ideas as to why the code above is returning only one record when it should be returning two?

Alan
 

Users who are viewing this thread

Back
Top Bottom