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!!!
9 2293
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. -
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
-
-
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, i) 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
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.
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: - If isPlanLocked(records!Year, intCounter) Then
i changed it, but it still is giving me problems; the same error
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.
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?
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.
Hey yall, got it working thanks for the tips there at the end... - 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 5
-
If i > 4 Then
-
i = 8
-
End If
-
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
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 ...
Sign in to post your reply or Sign up for a free account.
Similar topics
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. ...
|
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...
|
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...
|
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
...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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...
|
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...
|
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...
| | |