Below is the code used for printing all the bill by pressing one command button .The problem is that it prints only one bill only and not all the bills .Kindly check the code and guide me.
Dim BB As Long
'// LOADING THE BILL NUMBER
SQL = ""
BB = 0
SQL = "SELECT MAX([BILLNO])AS RR FROM [bill] WHERE [bill_date] >= #" & D11 & "#" _
& " AND [bill_date] <= #" & D21 & "#" _
& " AND [BName] = '" & Trim(ttax.CONAME) & "'"
comm.CommandText = SQL
Set res = New Recordset
Set res = comm.Execute
' MsgBox (res.RecordCount), , "The Recordcount "
If (IsNumeric(res!rr) = False) Then
BB = 0
' MsgBox (BB), , "The value of the Bill"
End If
If (IsNumeric(res!rr) = True) Then
BB = res!rr
' MsgBox (BB), , "The Current Value of the Bill"
End If
'// LOADING BILL NUMBER OVER
With frmBill
For i = 0 To .Combo1.ListCount - 1
'MsgBox "In the loop"
'// THE ACTUAL CALCULATION FOR PRINTING THE BILL
tless = LESS(.Combo1.List(i))
' MsgBox (BB), , "THE CURRENT BILL NUMBER"
'// LOADING THE LIST TRANSACTION FOR THE GIVEN PERIOD OF DATE
SQL = "SELECT * FROM [sales] WHERE [date] >= #" & CDate(frmBill.MD.Text) & " #" _
& " AND [date] <= #" & CDate(frmBill.MD2.Text) & "#" _
& " AND [CUname] = '" & Trim(.Combo1.List(i)) & "'" _
& " ORDER BY [date],[chall]"
comm.CommandText = SQL
Set res = New Recordset
Set res = comm.Execute
If (res.RecordCount > 0) Then
BB = BB + 1 '// INCREASING THE BILL NUMBER
Call TAX
'// DELETING THE PREVIOUS DATA FROM THE PRINT DATABASE
SQL = "DELETE FROM [print] "
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
'// SAVING THE RECORDS INTO THE PRINT TABLE
If (res.BOF = False) Then
res.MoveFirst
End If
'SAVING THE RECORDS TO THE BILL
Do While res.EOF = False
SQL = "UPDATE [sales] SET Rate = " & colL1.Item(res!Dis) _
& " WHERE [date] = #" & res!date & "#" _
& " AND [CUName] = '" & Trim(.Combo1.List(i)) & "'" _
& " AND [dis] = '" & res!Dis & "'" _
& " AND [chall] = " & res!CHALL
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (res.EOF = True) Then
Exit Do
End If
res.MoveNext
Loop
res.MoveFirst
Do While res.EOF = False
SQL = " INSERT INTO [print] ([BillNo],[BillDate],[name],[chall],[particulars],[nos],[rate],[total],[sal_tax],[ctax],[Form_Name],[Form_Number],[Other1],[Other2],[less],[surcharge],[words]) VALUES ( " _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& "'" & Trim(.Combo1.List(i)) & "'" & "," _
& res!CHALL & "," _
& "'" & Trim(res!Dis) & "'" & "," _
& res!qty & "," _
& colL1.Item(res!Dis) & "," _
& ((res!qty) * colL1.Item(res!Dis)) & "," _
& ttax.ST & "," _
& ttax.cst & "," _
& "'" & Trim(ttax.FORM_NUMBER) & "'" & "," _
& "'" & Trim(ttax.FORM_NAME) & "'" & "," _
& Val(ttax.OTHER1) & "," _
& 0 & "," _
& tless & "," _
& ttax.SURCHARGE & "," _
& "'" & Trim(wor) & "'" & ""
'MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (res.EOF = True) Then
Exit Do
End If
res.MoveNext
Loop
'// Setting for the printer
Printer.PrintQuality = vbPRPQMedium
'// PRINTING THE BILL ACCORDING TO THE COMPANY NAMES
If (ttax.CONAME = "Maru Industries" Then
CR1.ReportFileName = App.Path & "\Bill.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
End If
If (ttax.CONAME = "Maruti Industries" Then
CR1.ReportFileName = App.Path & "\Maruti.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
If (ttax.CONAME = "Suresh Welding Works" Then
CR1.ReportFileName = App.Path & "\Suresh.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
If (ttax.CONAME = "Merit Agriculture Works" Then
CR1.ReportFileName = App.Path & "\merit.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
'// UPDATING THE BILL FILE
Dim printed As Boolean
printed = True
SQL = "INSERT INTO [bill] ([CName],[BillNO],[Bill_date],[s_date],[E_date],[amount],[Printed],[st],[cst],[surcharge],[other1],[other2],[less],[FormName],[FormNum],[BName]) VALUES (" & "'" & Trim(.Combo1.List(i)) & "'" & "," _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& "#" & CDate(frmBill.MD.Text) & "#" & "," _
& "#" & CDate(frmBill.MD2.Text) & "#" & "," _
& CDbl(subtot) & "," _
& printed & "," _
& ttax.ST & "," _
& ttax.cst & "," _
& ttax.SURCHARGE & "," _
& ttax.OTHER1 & "," _
& 0 & "," _
& ttax.LESS & "," _
& "'" & Trim(frmBill.Text1.Text) & "'" & "," _
& "'" & Trim(frmBill.Text2.Text) & "'" & "," & "'" & Trim(ttax.CONAME) & "'" & ""
' MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
'// SAVING TO THE TAX FILE TO ADD SALES TAX AND CENTRAL TAX
'// FINDING OUT IF THE THE TAX IS ALREADY ENTERED
SQL = "SELECT COUNT(*) AS RR FROM [stax] " _
& "WHERE [billno] = " & BB _
& " AND [bill_date ] = #" & CDate(Me.Text3.Text) & "#" _
& " AND [BName] = '" & Trim(ttax.CONAME) & "'"
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (tres!rr < 1) Then
'// Adding the Sale tax
SQL = "INSERT INTO [stax] ([billno],[bill_date],[stax],[cst],[BName]) VALUES (" _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& CDbl(stax1) & "," _
& CDbl(cst) & "," & "'" & Trim(ttax.CONAME) & "'" & ""
'MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
Else
MsgBox ("TO EDIT THE BILL PLEASE SWITCH TO MAUNAL MODE", vbInformation, "Critical Error"
End If
End If
'// THIS SHOWS THE PROGRESS BAR VALUE
Me.Text2.Text = Val(Me.Text2.Text) + 1
pb1.Value = Int((CSng(Val(Text2.Text)) / CSng(Val(Text1.Text))) * 100)
Next i
End With
End Sub
Dim BB As Long
'// LOADING THE BILL NUMBER
SQL = ""
BB = 0
SQL = "SELECT MAX([BILLNO])AS RR FROM [bill] WHERE [bill_date] >= #" & D11 & "#" _
& " AND [bill_date] <= #" & D21 & "#" _
& " AND [BName] = '" & Trim(ttax.CONAME) & "'"
comm.CommandText = SQL
Set res = New Recordset
Set res = comm.Execute
' MsgBox (res.RecordCount), , "The Recordcount "
If (IsNumeric(res!rr) = False) Then
BB = 0
' MsgBox (BB), , "The value of the Bill"
End If
If (IsNumeric(res!rr) = True) Then
BB = res!rr
' MsgBox (BB), , "The Current Value of the Bill"
End If
'// LOADING BILL NUMBER OVER
With frmBill
For i = 0 To .Combo1.ListCount - 1
'MsgBox "In the loop"
'// THE ACTUAL CALCULATION FOR PRINTING THE BILL
tless = LESS(.Combo1.List(i))
' MsgBox (BB), , "THE CURRENT BILL NUMBER"
'// LOADING THE LIST TRANSACTION FOR THE GIVEN PERIOD OF DATE
SQL = "SELECT * FROM [sales] WHERE [date] >= #" & CDate(frmBill.MD.Text) & " #" _
& " AND [date] <= #" & CDate(frmBill.MD2.Text) & "#" _
& " AND [CUname] = '" & Trim(.Combo1.List(i)) & "'" _
& " ORDER BY [date],[chall]"
comm.CommandText = SQL
Set res = New Recordset
Set res = comm.Execute
If (res.RecordCount > 0) Then
BB = BB + 1 '// INCREASING THE BILL NUMBER
Call TAX
'// DELETING THE PREVIOUS DATA FROM THE PRINT DATABASE
SQL = "DELETE FROM [print] "
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
'// SAVING THE RECORDS INTO THE PRINT TABLE
If (res.BOF = False) Then
res.MoveFirst
End If
'SAVING THE RECORDS TO THE BILL
Do While res.EOF = False
SQL = "UPDATE [sales] SET Rate = " & colL1.Item(res!Dis) _
& " WHERE [date] = #" & res!date & "#" _
& " AND [CUName] = '" & Trim(.Combo1.List(i)) & "'" _
& " AND [dis] = '" & res!Dis & "'" _
& " AND [chall] = " & res!CHALL
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (res.EOF = True) Then
Exit Do
End If
res.MoveNext
Loop
res.MoveFirst
Do While res.EOF = False
SQL = " INSERT INTO [print] ([BillNo],[BillDate],[name],[chall],[particulars],[nos],[rate],[total],[sal_tax],[ctax],[Form_Name],[Form_Number],[Other1],[Other2],[less],[surcharge],[words]) VALUES ( " _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& "'" & Trim(.Combo1.List(i)) & "'" & "," _
& res!CHALL & "," _
& "'" & Trim(res!Dis) & "'" & "," _
& res!qty & "," _
& colL1.Item(res!Dis) & "," _
& ((res!qty) * colL1.Item(res!Dis)) & "," _
& ttax.ST & "," _
& ttax.cst & "," _
& "'" & Trim(ttax.FORM_NUMBER) & "'" & "," _
& "'" & Trim(ttax.FORM_NAME) & "'" & "," _
& Val(ttax.OTHER1) & "," _
& 0 & "," _
& tless & "," _
& ttax.SURCHARGE & "," _
& "'" & Trim(wor) & "'" & ""
'MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (res.EOF = True) Then
Exit Do
End If
res.MoveNext
Loop
'// Setting for the printer
Printer.PrintQuality = vbPRPQMedium
'// PRINTING THE BILL ACCORDING TO THE COMPANY NAMES
If (ttax.CONAME = "Maru Industries" Then
CR1.ReportFileName = App.Path & "\Bill.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
End If
If (ttax.CONAME = "Maruti Industries" Then
CR1.ReportFileName = App.Path & "\Maruti.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
If (ttax.CONAME = "Suresh Welding Works" Then
CR1.ReportFileName = App.Path & "\Suresh.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
If (ttax.CONAME = "Merit Agriculture Works" Then
CR1.ReportFileName = App.Path & "\merit.rpt"
CR1.DataFiles(0) = "D:\Maru\Maru.mdb"
CR1.Destination = crptToPrinter
CR1.PrintReport
Printer.EndDoc
'CR1.Action = crRunReport
End If
'// UPDATING THE BILL FILE
Dim printed As Boolean
printed = True
SQL = "INSERT INTO [bill] ([CName],[BillNO],[Bill_date],[s_date],[E_date],[amount],[Printed],[st],[cst],[surcharge],[other1],[other2],[less],[FormName],[FormNum],[BName]) VALUES (" & "'" & Trim(.Combo1.List(i)) & "'" & "," _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& "#" & CDate(frmBill.MD.Text) & "#" & "," _
& "#" & CDate(frmBill.MD2.Text) & "#" & "," _
& CDbl(subtot) & "," _
& printed & "," _
& ttax.ST & "," _
& ttax.cst & "," _
& ttax.SURCHARGE & "," _
& ttax.OTHER1 & "," _
& 0 & "," _
& ttax.LESS & "," _
& "'" & Trim(frmBill.Text1.Text) & "'" & "," _
& "'" & Trim(frmBill.Text2.Text) & "'" & "," & "'" & Trim(ttax.CONAME) & "'" & ""
' MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
'// SAVING TO THE TAX FILE TO ADD SALES TAX AND CENTRAL TAX
'// FINDING OUT IF THE THE TAX IS ALREADY ENTERED
SQL = "SELECT COUNT(*) AS RR FROM [stax] " _
& "WHERE [billno] = " & BB _
& " AND [bill_date ] = #" & CDate(Me.Text3.Text) & "#" _
& " AND [BName] = '" & Trim(ttax.CONAME) & "'"
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
If (tres!rr < 1) Then
'// Adding the Sale tax
SQL = "INSERT INTO [stax] ([billno],[bill_date],[stax],[cst],[BName]) VALUES (" _
& BB & "," _
& "#" & CDate(Me.Text3.Text) & "#" & "," _
& CDbl(stax1) & "," _
& CDbl(cst) & "," & "'" & Trim(ttax.CONAME) & "'" & ""
'MsgBox (SQL)
comm.CommandText = SQL
Set tres = New Recordset
Set tres = comm.Execute
Else
MsgBox ("TO EDIT THE BILL PLEASE SWITCH TO MAUNAL MODE", vbInformation, "Critical Error"
End If
End If
'// THIS SHOWS THE PROGRESS BAR VALUE
Me.Text2.Text = Val(Me.Text2.Text) + 1
pb1.Value = Int((CSng(Val(Text2.Text)) / CSng(Val(Text1.Text))) * 100)
Next i
End With
End Sub