473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Assistance with Open Recordset Or

I presume that using an open recordset method is the preferred method
of accomplishing what I'm trying to do. Of course, if there are other
options that would work, feel free to share them.

I need to provide a means of scanning one field for all records and to
trigger a message upon opening the form for alerting a user that
maintenance activities need to be promptly performed. The recordset
does not necessarily have to be used for any edits/updates as there is
another form that can be used to speed that task. Although indicating
the total number of records requiring maintenance would be a nice
enhancement.

Any assistance would be welcomed and appreciated. Thanks, Dalan
Private Sub Form_Activate()

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblItems", dbOpenTable)
Stock = rst!Stock
With rst
.MoveLast
.MoveFirst
If !Stock = "RS" Then
MsgBox "There are stock codes that require prompt changing."
End If
End With
rst.Close

Set rst = Nothing
Set dbs = Nothing

End Sub
Nov 12 '05 #1
4 3142
Try a DCount function.

Private Sub Form_Activate()
If DCount("*", "tblItems", "[Stock]='RS'") > 0 Then
MsgBox "There are stock codes that require prompt changing."
End If
End Sub

This will count the number of records in the table tblItems where
[Stock]='RS'. If there are more than zero, then that means there are some so
pop-up your message. This will be faster than trying to step through the
recordset.

Also, a problem with the recordset code as you have it. You open the
recordset, move last, then move first. Next, you check the value of [Stock].
This checks the value of [Stock] for the current record, in this case the
first record since you just did a move first. You're not checking all of the
records. To do that you would have to set up a loop, moving forward one
record at a time and checking the field for each record. The DCount function
will be much faster.

The Activate event runs each time you return to your form, causing it to
receive the focus. If the form is left open and just covered by another
form, then when you return to the form, the Activate event will run again.
If this is your intent, that's fine. If not, you may want to check the Open
and Load events of the form.

--
Wayne Morgan
MS Access MVP
"Dalan" <ot***@safe-mail.net> wrote in message
news:50**************************@posting.google.c om...
I presume that using an open recordset method is the preferred method
of accomplishing what I'm trying to do. Of course, if there are other
options that would work, feel free to share them.

I need to provide a means of scanning one field for all records and to
trigger a message upon opening the form for alerting a user that
maintenance activities need to be promptly performed. The recordset
does not necessarily have to be used for any edits/updates as there is
another form that can be used to speed that task. Although indicating
the total number of records requiring maintenance would be a nice
enhancement.

Any assistance would be welcomed and appreciated. Thanks, Dalan
Private Sub Form_Activate()

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblItems", dbOpenTable)
Stock = rst!Stock
With rst
.MoveLast
.MoveFirst
If !Stock = "RS" Then
MsgBox "There are stock codes that require prompt changing."
End If
End With
rst.Close

Set rst = Nothing
Set dbs = Nothing

End Sub

Nov 12 '05 #2
On 31 Jan 2004 03:38:47 -0800, ot***@safe-mail.net (Dalan) wrote:

Alternative: create a Totals query to get the count of rows with that
value in that field. MUCH faster, especially for larger sets.
select count(*) as RsCount from tblItems where Stock="RS"
Then open a recordset on that query, inspect the count, and if > 0
show your messagebox:
set rst=dbs.OpenRecordset("MyQuery", dbopensnapshot)
if rst!RsCount>0 then
Msgbox "There are stock..."
end if

-Tom.

I presume that using an open recordset method is the preferred method
of accomplishing what I'm trying to do. Of course, if there are other
options that would work, feel free to share them.

I need to provide a means of scanning one field for all records and to
trigger a message upon opening the form for alerting a user that
maintenance activities need to be promptly performed. The recordset
does not necessarily have to be used for any edits/updates as there is
another form that can be used to speed that task. Although indicating
the total number of records requiring maintenance would be a nice
enhancement.

Any assistance would be welcomed and appreciated. Thanks, Dalan
Private Sub Form_Activate()

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblItems", dbOpenTable)
Stock = rst!Stock
With rst
.MoveLast
.MoveFirst
If !Stock = "RS" Then
MsgBox "There are stock codes that require prompt changing."
End If
End With
rst.Close

Set rst = Nothing
Set dbs = Nothing

End Sub


Nov 12 '05 #3
> I need to provide a means of scanning one field for all records and to
trigger a message upon opening the form for alerting a user that
maintenance activities need to be promptly performed. The recordset
does not necessarily have to be used for any edits/updates as there is
another form that can be used to speed that task. Although indicating
the total number of records requiring maintenance would be a nice
enhancement.


If you're doing this based on a count, you could use DCOUNT or open a
recordset based on SQL statement with a WHERE clause. Looping through
all the records in a table is overkill.
Nov 12 '05 #4
Thanks all for your suggestions and advice. I will give it a go today.
I would also like to say thanks to everyone who has provided helpful
assistance over the last few months. It has been genuinely appreciated
- keep up the good work. Dalan
Try a DCount function.

Private Sub Form_Activate()
If DCount("*", "tblItems", "[Stock]='RS'") > 0 Then
MsgBox "There are stock codes that require prompt changing."
End If
End Sub

This will count the number of records in the table tblItems where
[Stock]='RS'. If there are more than zero, then that means there are
some so
pop-up your message. This will be faster than trying to step through
the
recordset.

Also, a problem with the recordset code as you have it. You open the
recordset, move last, then move first. Next, you check the value of
[Stock].
This checks the value of [Stock] for the current record, in this case
the
first record since you just did a move first. You're not checking all
of the
records. To do that you would have to set up a loop, moving forward
one
record at a time and checking the field for each record. The DCount
function
will be much faster.

The Activate event runs each time you return to your form, causing it
to
receive the focus. If the form is left open and just covered by
another
form, then when you return to the form, the Activate event will run
again.
If this is your intent, that's fine. If not, you may want to check the
Open
and Load events of the form.

--
Wayne Morgan
MS Access MVP

Alternative: create a Totals query to get the count of rows with that
value in that field. MUCH faster, especially for larger sets.
select count(*) as RsCount from tblItems where Stock="RS"
Then open a recordset on that query, inspect the count, and if > 0
show your messagebox:
set rst=dbs.OpenRecordset("MyQuery", dbopensnapshot)
if rst!RsCount>0 then
Msgbox "There are stock..."
end if

-Tom van Stiphout

If you're doing this based on a count, you could use DCOUNT or open a
recordset based on SQL statement with a WHERE clause. Looping through
all the records in a table is overkill.

Pieter Linden

I presume that using an open recordset method is the preferred method
of accomplishing what I'm trying to do. Of course, if there are other
options that would work, feel free to share them.

I need to provide a means of scanning one field for all records and to
trigger a message upon opening the form for alerting a user that
maintenance activities need to be promptly performed. The recordset
does not necessarily have to be used for any edits/updates as there is
another form that can be used to speed that task. Although indicating
the total number of records requiring maintenance would be a nice
enhancement.

Any assistance would be welcomed and appreciated. Thanks, Dalan
Private Sub Form_Activate()

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblItems", dbOpenTable)
Stock = rst!Stock
With rst
.MoveLast
.MoveFirst
If !Stock = "RS" Then
MsgBox "There are stock codes that require prompt changing."
End If
End With
rst.Close

Set rst = Nothing
Set dbs = Nothing

End Sub
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Endora | last post by:
Hello, The database I'm working with has these 2 fields: - "CD", which stands for "Consolidated Design Number" (not Compact DISC) and - "URL", which is the full URL (http://...)
1
by: Dalan | last post by:
I have tried both methods of using DSum and creating a Function to address summing some number columns, but to no avail. Since this has been a popular topic over the years, I'm sure I'll receive...
1
by: Dalan | last post by:
I'm experiencing a Query Syntax Error with an Access 97 Db. Actually, the query performs as expected when adding any new records or editing existing ones and even deleting records, EXCEPT when the...
2
by: Colleyville Alan | last post by:
I ran into problems in an app in which I received a msg of "cannot lock the table, it is in use by another user". It turns out that I had opened a recordset with a command like set rstmyrecs =...
2
by: Sunil Korah | last post by:
I am having some trouble with opening recordsets. I have used code more or less straight from the access help. But still I am getting some errors. I am unable to work out what exactly I am doing...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
8
by: metalheadstorm | last post by:
ok ive set up a connection between my access db ( 97) and my vb6 interface and this is what i got form_load Data6.DatabaseName = App.Path & "\cjmillers.mdb" Data6.RecordSource = "select * from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.