473,407 Members | 2,326 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,407 software developers and data experts.

Error when moving to next record, runtime error '3021' for i

105 100+
i need some help

i have a table with 5 city divisions

1 = D1
2 = D2
3 = D3
4 = D4

and

8 = D5

I am trying to write a For loop in within a while statement that will search not only 1 To 4, but also 8 as well. I have tried...For 1 To 4 Or 8 as code but that doesn't work. After my code reads the first 4 divisions it tries to read the integer 5, and i don't have a 5; i have an 8. I am using 5, 6, and 7 for other important things. How can I accomplish reading my 8 integer division in my tbl?

my code:

Public Function ExportPlanReports(path As String)

Dim years As String
Dim dbo As Database
Dim records As Recordset
Dim sqlStatement As String
Dim i As Integer

sqlStatement = "SELECT tblPlanExtra.Year FROM tblPlanExtra WHERE tblPlanExtra.Year >= " & getPlanStartingYear & " GROUP BY tblPlanExtra.Year ORDER BY tblPlanExtra.Year;"

Set dbo = CurrentDb
Set records = dbo.OpenRecordset(sqlStatement)

While Not records.EOF
For i = 1 To 4
If isPlanLocked(records!Year, i) Then
Forms!frmMain!frameDivision.value = i
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next i
records.MoveNext
Wend

records.Close

End Function

thanks for your help in advance!!!
Dec 28 '07 #1
9 2293
ADezii
8,834 Expert 8TB
i need some help

i have a table with 5 city divisions

1 = D1
2 = D2
3 = D3
4 = D4

and

8 = D5

I am trying to write a For loop in within a while statement that will search not only 1 To 4, but also 8 as well. I have tried...For 1 To 4 Or 8 as code but that doesn't work. After my code reads the first 4 divisions it tries to read the integer 5, and i don't have a 5; i have an 8. I am using 5, 6, and 7 for other important things. How can I accomplish reading my 8 integer division in my tbl?

my code:

Public Function ExportPlanReports(path As String)

Dim years As String
Dim dbo As Database
Dim records As Recordset
Dim sqlStatement As String
Dim i As Integer

sqlStatement = "SELECT tblPlanExtra.Year FROM tblPlanExtra WHERE tblPlanExtra.Year >= " & getPlanStartingYear & " GROUP BY tblPlanExtra.Year ORDER BY tblPlanExtra.Year;"

Set dbo = CurrentDb
Set records = dbo.OpenRecordset(sqlStatement)

While Not records.EOF
For i = 1 To 4
If isPlanLocked(records!Year, i) Then
Forms!frmMain!frameDivision.value = i
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next i
records.MoveNext
Wend

records.Close

End Function

thanks for your help in advance!!!
I'm not 100% sure that I understand your exact request, but using this code within your code body may be the answer. If this is not the case, please explain your situation in more detail.
Expand|Select|Wrap|Line Numbers
  1. Dim aintDivisions(1 To 5) As Integer, intCounter As Integer
  2.  
  3. aintDivisions(1) = 1
  4. aintDivisions(2) = 2
  5. aintDivisions(3) = 3
  6. aintDivisions(4) = 4
  7. aintDivisions(5) = 8
  8.  
  9. Do While Not records.EOF
  10.   'Test for specific values of 1, 2, 3, 4, and 8
  11.   For intCounter = LBound(aintDivisions) To UBound(aintDivisions)
  12.     If isPlanLocked(records!Year, i) Then
  13.       Forms!frmMain!frameDivision.Value = intCounter
  14.       DoCmd.OpenForm "frmPlan"
  15.       Forms!frmPlan!txtYear.Value = records!Year
  16.       DoCmd.OpenForm "frmPrintPlan"
  17.       PrintPlan
  18.       DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", Path & Forms!frmPlan!txtYear.Value & _
  19.                                      " " & FindDivisionName(Forms!frmMain!frameDivision.Value) & ".snp"
  20.       DoCmd.Close acReport, "rptPlan"
  21.       DoCmd.Close acForm, "frmPrintPlan"
  22.       DoCmd.Close acForm, "frmPlan"
  23.     End If
  24.   Next intCounter
  25.   records.MoveNext
  26. Loop
Dec 28 '07 #2
jmarcrum
105 100+
There's still an error in my code. The function isPlanLocked is where the error lies...

Public Function ExportPlanReports(path As String)

Dim years As String
Dim dbo As Database
Dim records As Recordset
Dim sqlStatement As String
Dim aintDivisions(1 To 5) As Integer, intCounter As Integer

aintDivisions(1) = 1
aintDivisions(2) = 2
aintDivisions(3) = 3
aintDivisions(4) = 4
aintDivisions(5) = 8

sqlStatement = "SELECT tblPlanExtra.Year FROM tblPlanExtra WHERE tblPlanExtra.Year >= " & getPlanStartingYear & " GROUP BY tblPlanExtra.Year ORDER BY tblPlanExtra.Year;"

Set dbo = CurrentDb
Set records = dbo.OpenRecordset(sqlStatement)

Do While Not records.EOF
'Test for specific values of 1, 2, 3, 4, and 8
For intCounter = LBound(aintDivisions) To UBound(aintDivisions)
If isPlanLocked(records!Year, intCounter) Then
Forms!frmMain!frameDivision.value = intCounter
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next intCounter
records.MoveNext
Loop

records.Close

End Function

-----------------------------------------------------------------------------

Public Function isPlanLocked(Year As Integer, Div As Integer) As Boolean
Dim Locked As Boolean

Dim dbs_curr As Database
Dim record As Recordset
Dim value As Boolean

sqlStatement = "SELECT tblPlanExtra.Locked FROM tblPlanExtra WHERE ((tblPlanExtra.Year = " & Year & ") AND (tblPlanExtra.Division = " & Div & "));"


Set dbs_curr = CurrentDb
Set record = dbs_curr.OpenRecordset(sqlStatement)

Locked = record("Locked")

record.Close
isPlanLocked = Locked

End Function

------------------------------------------------------------------------------

in the isPlanLocked function, the error is on the Locked = record("Locked") line...above that, when I let my cursor hover over the sqlstatement line, the Div is set to "5" and I still do not have a 5 in my table, it's an 8.
Dec 28 '07 #3
ADezii
8,834 Expert 8TB
There's still an error in my code. The function isPlanLocked is where the error lies...

Public Function ExportPlanReports(path As String)

Dim years As String
Dim dbo As Database
Dim records As Recordset
Dim sqlStatement As String
Dim aintDivisions(1 To 5) As Integer, intCounter As Integer

aintDivisions(1) = 1
aintDivisions(2) = 2
aintDivisions(3) = 3
aintDivisions(4) = 4
aintDivisions(5) = 8

sqlStatement = "SELECT tblPlanExtra.Year FROM tblPlanExtra WHERE tblPlanExtra.Year >= " & getPlanStartingYear & " GROUP BY tblPlanExtra.Year ORDER BY tblPlanExtra.Year;"

Set dbo = CurrentDb
Set records = dbo.OpenRecordset(sqlStatement)

Do While Not records.EOF
'Test for specific values of 1, 2, 3, 4, and 8
For intCounter = LBound(aintDivisions) To UBound(aintDivisions)
If isPlanLocked(records!Year, intCounter) Then
Forms!frmMain!frameDivision.value = intCounter
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next intCounter
records.MoveNext
Loop

records.Close

End Function

-----------------------------------------------------------------------------

Public Function isPlanLocked(Year As Integer, Div As Integer) As Boolean
Dim Locked As Boolean

Dim dbs_curr As Database
Dim record As Recordset
Dim value As Boolean

sqlStatement = "SELECT tblPlanExtra.Locked FROM tblPlanExtra WHERE ((tblPlanExtra.Year = " & Year & ") AND (tblPlanExtra.Division = " & Div & "));"


Set dbs_curr = CurrentDb
Set record = dbs_curr.OpenRecordset(sqlStatement)

Locked = record("Locked")

record.Close
isPlanLocked = Locked

End Function

------------------------------------------------------------------------------

in the isPlanLocked function, the error is on the Locked = record("Locked") line...above that, when I let my cursor hover over the sqlstatement line, the Div is set to "5" and I still do not have a 5 in my table, it's an 8.
Try changing Line #12 to:
Expand|Select|Wrap|Line Numbers
  1. If isPlanLocked(records!Year, intCounter) Then
Dec 28 '07 #4
jmarcrum
105 100+
i changed it, but it still is giving me problems; the same error
Dec 28 '07 #5
jaxjagfan
254 Expert 100+
Have you tried this:

While Not records.EOF
For i >= 8
If isPlanLocked(records!Year, i) Then
Forms!frmMain!frameDivision.value = i
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next i
If i > 4 then
i = 8
End if
records.MoveNext
Wend

The if at bottom would look for and change i to 8 if greater than 4. Thus bypassing 5-7.
Dec 28 '07 #6
ADezii
8,834 Expert 8TB
Have you tried this:

While Not records.EOF
For i >= 8
If isPlanLocked(records!Year, i) Then
Forms!frmMain!frameDivision.value = i
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next i
If i > 4 then
i = 8
End if
records.MoveNext
Wend

The if at bottom would look for and change i to 8 if greater than 4. Thus bypassing 5-7.
The whole concept behind placing legitimate values into a Fixed Array was to avoid that type of comparison, why are you still using it?
Dec 28 '07 #7
jmarcrum
105 100+
Have you tried this:

While Not records.EOF
For i >= 8
If isPlanLocked(records!Year, i) Then
Forms!frmMain!frameDivision.value = i
DoCmd.OpenForm "frmPlan"
Forms!frmPlan!txtYear.value = records!Year
DoCmd.OpenForm "frmPrintPlan"
PrintPlan
DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value ) & ".snp"
DoCmd.Close acReport, "rptPlan"
DoCmd.Close acForm, "frmPrintPlan"
DoCmd.Close acForm, "frmPlan"
End If
Next i
If i > 4 then
i = 8
End if
records.MoveNext
Wend

The if at bottom would look for and change i to 8 if greater than 4. Thus bypassing 5-7.

Now that gives me an error on the For i >=8 line, it says = is expected there.
Dec 28 '07 #8
jmarcrum
105 100+
Hey yall, got it working thanks for the tips there at the end...

Expand|Select|Wrap|Line Numbers
  1. Public Function ExportPlanReports(path As String)
  2.  
  3. Dim years As String
  4. Dim dbo As Database
  5. Dim records As Recordset
  6. Dim sqlStatement As String
  7. Dim i As Integer
  8.  
  9. sqlStatement = "SELECT tblPlanExtra.Year FROM tblPlanExtra WHERE tblPlanExtra.Year >= " & getPlanStartingYear & " GROUP BY tblPlanExtra.Year ORDER BY tblPlanExtra.Year;"
  10.  
  11. Set dbo = CurrentDb
  12. Set records = dbo.OpenRecordset(sqlStatement)
  13.  
  14. While Not records.EOF
  15.     For i = 1 To 5
  16.     If i > 4 Then
  17.         i = 8
  18.     End If
  19.         If isPlanLocked(records!Year, i) Then
  20.             Forms!frmMain!frameDivision.value = i
  21.             DoCmd.OpenForm "frmPlan"
  22.             Forms!frmPlan!txtYear.value = records!Year
  23.             DoCmd.OpenForm "frmPrintPlan"
  24.             PrintPlan
  25.             DoCmd.OutputTo acOutputReport, "rptPlan", "Snapshot Format", path & Forms!frmPlan!txtYear.value & " " & FindDivisionName(Forms!frmMain!frameDivision.value) & ".snp"
  26.             DoCmd.Close acReport, "rptPlan"
  27.             DoCmd.Close acForm, "frmPrintPlan"
  28.             DoCmd.Close acForm, "frmPlan"
  29.         End If
  30.     Next i
  31.     records.MoveNext
  32. Wend
  33. records.Close
  34.  
  35. End Function
Dec 28 '07 #9
jaxjagfan
254 Expert 100+
Glad we could be of assistance. I saw a possible solution to your problem without increasing the complexity of your code. It may not be the "Preferred" method of getting there but ...
Dec 28 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
2
by: Polly | last post by:
I'm trying to write the results of a query, a name, ID number, and date out to a notepad .txt file to print on a "legacy" printer. I get the output from the first 2 "write" lines over the...
0
by: Jamey | last post by:
I perused old posts for an answer to this for at least an hour, and I've found a work-around, but no definitive answer. Synopsis of the problem: On NotInList or ctl.Requery commands where a...
3
by: windandwaves | last post by:
Hi, I am trying to make errors a bit more meaningful for my users. I am trying to fix error 3201 where there is a missing field in a form. If I do not do any error trapping, then I get ...
2
by: Robert | last post by:
I have a label on my form lblCount and the following code in my form for displaying a record count: Private Sub Form_Current() Me.RecordsetClone.Bookmark = Me.Bookmark Me!lblCount.Caption =...
7
by: ruvi | last post by:
I am getting runtime error 3021 - Either EOF or BOF is true or the current record has been deleted..... I have 2 combo boxes in a form- One for the client and the other for the project. When the...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
8
by: fish919 | last post by:
Hello All, I am having a little trouble with my database. The Database has a parent table with 5 or 6 children tables in it they are linked by a common id filed. The problem is that the...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.