PC Review


Reply
Thread Tools Rate Thread

DAO OpenRecordset no errors but not returning any records.

 
 
pauldennis
Guest
Posts: n/a
 
      20th Mar 2006
I have a query that looks at the T_AVAILABILITY table and then calls this
module. The idea of the module is to find all other records in this table
(T_AVAILABILITY) where ITEM is the same. I will need to do some complex
calculation once I can work out how to loop through the table based on the
ITEM.

So far I have the code below and the syntax seems fine, i.e. no error,
however at no point does the fields returned seem to be populated. Can you
help?

Function Availability(E_ITEM As String, E_SEVERITY As Integer, E_PROBLEM_ID
As String) As String
On Error GoTo Err_Availability

Dim intCount As Integer
Dim rst As DAO.Recordset
Dim strItem As String
Dim strSQL As String
Dim DB As DAO.Database

Set DB = CurrentDb
strSQL = "SELECT ITEM, SEVERITY, PROBLEM_ID " & _
"FROM T_AVAILABILITY " & _
"ORDER BY ITEM;"
Set rst = CurrentDb.OpenRecordset(strSQL)

strItem = "ITEM = '" & E_ITEM & "'"
rst.FindFirst strItem
Availability = PROBLEM_ID
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      20th Mar 2006
"pauldennis" <u19890@uwe> wrote in message news:5d8bba7b11502@uwe
> I have a query that looks at the T_AVAILABILITY table and then calls
> this module. The idea of the module is to find all other records in
> this table (T_AVAILABILITY) where ITEM is the same. I will need to do
> some complex calculation once I can work out how to loop through the
> table based on the ITEM.
>
> So far I have the code below and the syntax seems fine, i.e. no error,
> however at no point does the fields returned seem to be populated.
> Can you help?
>
> Function Availability(E_ITEM As String, E_SEVERITY As Integer,
> E_PROBLEM_ID As String) As String
> On Error GoTo Err_Availability
>
> Dim intCount As Integer
> Dim rst As DAO.Recordset
> Dim strItem As String
> Dim strSQL As String
> Dim DB As DAO.Database
>
> Set DB = CurrentDb
> strSQL = "SELECT ITEM, SEVERITY, PROBLEM_ID " & _
> "FROM T_AVAILABILITY " & _
> "ORDER BY ITEM;"
> Set rst = CurrentDb.OpenRecordset(strSQL)
>
> strItem = "ITEM = '" & E_ITEM & "'"
> rst.FindFirst strItem
> Availability = PROBLEM_ID


At the least, you need to qualify PROBLEM_ID with a reference to the
recordset:

Availability = rst!PROBLEM_ID

Also, you need to check to make sure the recordset is not empty, and
that the FindFirst call finds a matching record. Making minimal
modifications to your current code, that would look like this:

' ...

Set rst = CurrentDb.OpenRecordset(strSQL)

If Not rst.EOF Then
rst.FindFirst strItem
If Not rst.NoMatch Then
Availability = rst!PROBLEM_ID
End If
End If

' ...

If you're only looking up one item in this function, though, it makes
more sense to open the recordset on a query that returns just records
for that item:

strSQL = _
"SELECT ITEM, SEVERITY, PROBLEM_ID " & _
"FROM T_AVAILABILITY " & _
"WHERE ITEM = '" & E_ITEM & "'"

Set rst = CurrentDb.OpenRecordset(strSQL)

If Not rst.EOF Then
Availability = rst!PROBLEM_ID
End If


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Alex Dybenko
Guest
Posts: n/a
 
      20th Mar 2006
Hi,
instead for using rst.FindFirst much more efficient to filter by item in
SQL:
strSQL = "SELECT ITEM, SEVERITY, PROBLEM_ID " & _
"FROM T_AVAILABILITY " & _
"Where BY ITEM='" & E_ITEM & "'

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com



"pauldennis" <u19890@uwe> wrote in message news:5d8bba7b11502@uwe...
>I have a query that looks at the T_AVAILABILITY table and then calls this
> module. The idea of the module is to find all other records in this table
> (T_AVAILABILITY) where ITEM is the same. I will need to do some complex
> calculation once I can work out how to loop through the table based on the
> ITEM.
>
> So far I have the code below and the syntax seems fine, i.e. no error,
> however at no point does the fields returned seem to be populated. Can you
> help?
>
> Function Availability(E_ITEM As String, E_SEVERITY As Integer,
> E_PROBLEM_ID
> As String) As String
> On Error GoTo Err_Availability
>
> Dim intCount As Integer
> Dim rst As DAO.Recordset
> Dim strItem As String
> Dim strSQL As String
> Dim DB As DAO.Database
>
> Set DB = CurrentDb
> strSQL = "SELECT ITEM, SEVERITY, PROBLEM_ID " & _
> "FROM T_AVAILABILITY " & _
> "ORDER BY ITEM;"
> Set rst = CurrentDb.OpenRecordset(strSQL)
>
> strItem = "ITEM = '" & E_ITEM & "'"
> rst.FindFirst strItem
> Availability = PROBLEM_ID


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a query that opens but errors on Set qry=currentDB.Openrecordset() roger Microsoft Access Form Coding 2 15th Feb 2008 12:39 PM
DAO;OpenRecordset;dbInconsistent option affects number of records =?Utf-8?B?TWlndWVsIEdhbmlsaG8gU2FudG9z?= Microsoft Access VBA Modules 0 30th Oct 2007 11:26 AM
OpenRecordSet returns incorrect number of records =?Utf-8?B?Sm9lIENsZXRjaGVy?= Microsoft Access VBA Modules 3 24th Oct 2006 07:01 PM
Seagate drive check utility reports "errors in metadatea file records, other errors critical errors in metadata.." LQQK@mi.sig Storage Devices 0 3rd Feb 2006 04:48 AM
Errors with OpenRecordset J Labar Microsoft Access Form Coding 4 9th Sep 2004 04:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.