Need help with querying a table using a filter.

G

Guest

This is my basic process data routine:

Public Sub ProcessData()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim dblComValue as Double

Set rst = dbs.OpenRecordset("tblData", dbOpenDynaset)

With rst
.MoveFirst
Do While Not .EOF
If ![idsTypeID] = 1 then
dblComValue = ![dblCom04]
else
dblComValue = ![dblCom05]
endif
.MoveNext
Loop
End With

Set rst = Nothing
End Sub

How do I modify ProcessData() to open tblData with a filter so I only get
the subset of rows where intOrderType = 2?
 
G

Gijs Beukenoot

Al drukte met precisie uit :
This is my basic process data routine:

Public Sub ProcessData()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim dblComValue as Double

Set rst = dbs.OpenRecordset("tblData", dbOpenDynaset)

With rst
.MoveFirst
Do While Not .EOF
If ![idsTypeID] = 1 then
dblComValue = ![dblCom04]
else
dblComValue = ![dblCom05]
endif
.MoveNext
Loop
End With

Set rst = Nothing
End Sub

How do I modify ProcessData() to open tblData with a filter so I only get
the subset of rows where intOrderType = 2?

Would
Set rst = dbs.OpenRecordset("SELECT * FROM tblData WHERE
intOrdertype=2", dbOpenDynaset)
be sufficient?
 
G

Guest

Thanks Gijs that worked fine. I reduced loop interations from 99 to 50.

Al

Gijs Beukenoot said:
Al drukte met precisie uit :
This is my basic process data routine:

Public Sub ProcessData()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim dblComValue as Double

Set rst = dbs.OpenRecordset("tblData", dbOpenDynaset)

With rst
.MoveFirst
Do While Not .EOF
If ![idsTypeID] = 1 then
dblComValue = ![dblCom04]
else
dblComValue = ![dblCom05]
endif
.MoveNext
Loop
End With

Set rst = Nothing
End Sub

How do I modify ProcessData() to open tblData with a filter so I only get
the subset of rows where intOrderType = 2?

Would
Set rst = dbs.OpenRecordset("SELECT * FROM tblData WHERE
intOrdertype=2", dbOpenDynaset)
be sufficient?
 

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