Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 112 votes, 5.00 average. Display Modes
Old 12-22-2011, 02:12 PM   #1
Kookie22
Newly Registered User
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Kookie22 is on a distinguished road
Frustrating Runtime error access 3021

Hey guys..

As of Monday a access document started producing a runtime error 3021.
I've tried googling how to fix this but can't figure out how to do it and have spent quite a few hours on this..

wondering if someone would be nice enough to lend some help.

When I run it in debug mode it references the rst.MoveFirst as the error.

here is the code:





msg = "Your new Schedule Year is: " & sched_year & Chr(10)
msg = msg & "The new Pay Period is: " & sched_period & Chr(10) & Chr(10)
msg = msg & "Click OK to create this schedule for" & Chr(10)
msg = msg & "all of your employees or Click CANCEL."

If MsgBox(msg, vbOKCancel) = vbCancel Then
Exit Sub
End If

str = "Select * From [Pay Period Dates] Where [Year_ID]=" & sched_year & " and [Pay Period]=" & sched_period
Set rst = dbs.OpenRecordset(str)

rst.MoveFirst
rst.MoveLast

If rst.RecordCount = 1 Then

str = "Select * From [Employees] Where [DEP_ID]='" & Forms![Login Screen]![Department] & "' and [Status]<>'" & "Terminated" & "'"
Set emp = dbs.OpenRecordset(str)
Set post = dbs.OpenRecordset("Employees Hours")

If emp.RecordCount = 0 Then
msg = "No Employess found in database!"
MsgBox msg, vbCritical, "Auto Create New Pay Period"
Exit Sub
End If

emp.MoveLast
emp.MoveFirst

Do Until emp.EOF

sched_date = rst![Start Date]
End_Date = rst![End Date]
sched_week = 0

Do Until sched_date > End_Date

post.AddNew
--

Thanks so much for your time

Kookie22 is offline   Reply With Quote
Old 12-22-2011, 02:21 PM   #2
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 30,927
Thanks: 8
Thanked 3,662 Times in 3,605 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Frustrating Runtime error access 3021

What is a 3021 error? Offhand, that line would error if the recordset didn't return any records. Use this to make sure it is:

http://www.baldyweb.com/ImmediateWindow.htm
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 12-22-2011, 02:23 PM   #3
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,802 Times in 1,572 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Re: Frustrating Runtime error access 3021

Sounds like there are no records being returned for the criteria and so you can't move first if there is nothing. Also, just an FYI - when a recordset is opened, it is ALWAYS at the first so you do not need to use rst.MoveFirst before the rst.MoveLast but you may need to check for records first -

If rst.RecordCount > 0 Then

(you can do that without moving first because if there are no records it will be 0 but if there are it will at least be 1 even if you haven't moved last yet).

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 12-22-2011, 02:25 PM   #4
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,802 Times in 1,572 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Re: Frustrating Runtime error access 3021

Hmm, I was a bit slow on that response.


__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RunTime Error 3021 No Current Record dyrueta Modules & VBA 1 08-22-2011 01:31 PM
Access 2010 Error 3021 while porting code from Access 2007 :: Help Request basstard80 General 19 08-04-2011 02:03 PM
3021 Runtime Error Nannab Modules & VBA 4 02-07-2010 11:00 PM
Still suffering from Delete runtime error 3021 Wegets7 Modules & VBA 22 11-08-2004 07:52 AM
Runtime error 3021 Len Lee Forms 2 01-31-2003 04:58 AM




All times are GMT -8. The time now is 04:46 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World