crawfordfr
New member
- Local time
- Today, 03:19
- Joined
- May 11, 2023
- Messages
- 7
Hi Not even sure this is the correct area but not sure where else to look. I did do a search in the forums for similar topics but didnt find any. Did google searches and found matches but no fixes that actually help me. I was thinking mayb the report area as well. Feel free to move if it dont belong!
Anyways I have this form which lists all my Files/Clients in arrears. I cycle through a recordset and calculate all the balances and then display on this form!
If I click the Print to screen button it des the following:
1) Cycle through the listbox
2) Looks for all Bills matching the ID
3) Grabs the highest bill number
4) Builds a string containign all the Bills compared to the list (based on #3)
5) builds a where clause based on #4 to pass to the open report command
Problem is I get the following error. Is there another way I can achieve what I want?
NOTE: This works perfectly well with lets say 100 records but crashes when its a lot of records!
The VBA CODE is listed below.
Private Sub cmdPrintBills_Click()
Dim i As Integer
Dim strSQL As String
Dim strMaxBillId As String
Dim rstLookup As Recordset
Dim strWhereClause As String
On Error GoTo ErrorHandler
strMaxBillId = 0
strWhereClause = "1=1"
For i = 1 To Me.lstFiles.ListCount - 1 ' For each record in the listbox
' Select the newly inserted record
strSQL = "SELECT max(bil_id) as MaxBillId FROM TBILLS WHERE fil_id = " & Me.lstFiles.ItemData(i)
' MsgBox (strSQL)
' Open the RecordSet
Set rstLookup = dbsPBHr.OpenRecordset(strSQL, dbOpenSnapshot)
If rstLookup!MaxBillId > 0 Then
strMaxBillId = strMaxBillId & ", " & rstLookup!MaxBillId
End If
Next i
strWhereClause = strWhereClause & " AND bil_id IN (" & strMaxBillId & ")"
' lngPBWhereClause = "1=1 " & strWhereClause
DoCmd.OpenReport "repBillArrears", acViewPreview, , strWhereClause
ErrorHandler:
Select Case Err.Number
' no Real error
Case 0
' Pass the message to the user
Case Else
Call MsgBox("A fatal error occured, contact the IT Section! The error details will be displayed in the next message box!", 16, "System Error")
Call MsgBox("Form = frmrepFilesinArrears, Procedure = cmdPrintBills_Click, Error number = " & Err.Number & ", Error description = " & Err.Description, 16, "System Error")
End Select
End Sub
Anyways I have this form which lists all my Files/Clients in arrears. I cycle through a recordset and calculate all the balances and then display on this form!
If I click the Print to screen button it des the following:
1) Cycle through the listbox
2) Looks for all Bills matching the ID
3) Grabs the highest bill number
4) Builds a string containign all the Bills compared to the list (based on #3)
5) builds a where clause based on #4 to pass to the open report command
Problem is I get the following error. Is there another way I can achieve what I want?
NOTE: This works perfectly well with lets say 100 records but crashes when its a lot of records!
The VBA CODE is listed below.
Private Sub cmdPrintBills_Click()
Dim i As Integer
Dim strSQL As String
Dim strMaxBillId As String
Dim rstLookup As Recordset
Dim strWhereClause As String
On Error GoTo ErrorHandler
strMaxBillId = 0
strWhereClause = "1=1"
For i = 1 To Me.lstFiles.ListCount - 1 ' For each record in the listbox
' Select the newly inserted record
strSQL = "SELECT max(bil_id) as MaxBillId FROM TBILLS WHERE fil_id = " & Me.lstFiles.ItemData(i)
' MsgBox (strSQL)
' Open the RecordSet
Set rstLookup = dbsPBHr.OpenRecordset(strSQL, dbOpenSnapshot)
If rstLookup!MaxBillId > 0 Then
strMaxBillId = strMaxBillId & ", " & rstLookup!MaxBillId
End If
Next i
strWhereClause = strWhereClause & " AND bil_id IN (" & strMaxBillId & ")"
' lngPBWhereClause = "1=1 " & strWhereClause
DoCmd.OpenReport "repBillArrears", acViewPreview, , strWhereClause
ErrorHandler:
Select Case Err.Number
' no Real error
Case 0
' Pass the message to the user
Case Else
Call MsgBox("A fatal error occured, contact the IT Section! The error details will be displayed in the next message box!", 16, "System Error")
Call MsgBox("Form = frmrepFilesinArrears, Procedure = cmdPrintBills_Click, Error number = " & Err.Number & ", Error description = " & Err.Description, 16, "System Error")
End Select
End Sub