K
Krishnakanth
For eg. I am having a table details.
I need to read a record from a table one by one and insert it into the
report. For that I have written the code as follows.
___________________________________________________________
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ename, ecode, year, month
Dim loanperdiem, loansalary
eyear = 2008
emonth = 2
'----DB ----------
Dim conObj As ADODB.Connection
Set conObj = New ADODB.Connection
conObj.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='D:\ajdata1\Acc_Rpt.mdb';")
Dim ar1 As ADODB.Recordset
Set ar1 = New ADODB.Recordset
Dim empName, SSN, empcode
ar1.Open "Select Name, Employee_code, SSN from Salary_Details", conObj
If ar1.BOF = False Then
Do While Not ar1.EOF
ename = ar1(0)
ecode = ar1(1)
essn = ar1(2)
Me.Text162 = ename
Me.Text164 = ecode
Me.Text166 = essn
ar1.MoveNext
Loop
conObj.Close
End If
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No records found !", vbExclamation, "No Records"
Cancel = True
End Sub
___________________________________________________________
After running this report, only the last record will be displayed in the
report. There are 4 rows/record in the table Salary_Details. Hence I am
expecting 4 rows to be displayed in the report.
Note: I know that the above task can also be achieved by clicking the
properties of the report. and we have to select the record source as the
"salary_details" (table name/query name). But I don't want to do in this way.
Can anyone help me how to do that.
Krishnakanth VM
Software Engineer
I need to read a record from a table one by one and insert it into the
report. For that I have written the code as follows.
___________________________________________________________
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ename, ecode, year, month
Dim loanperdiem, loansalary
eyear = 2008
emonth = 2
'----DB ----------
Dim conObj As ADODB.Connection
Set conObj = New ADODB.Connection
conObj.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='D:\ajdata1\Acc_Rpt.mdb';")
Dim ar1 As ADODB.Recordset
Set ar1 = New ADODB.Recordset
Dim empName, SSN, empcode
ar1.Open "Select Name, Employee_code, SSN from Salary_Details", conObj
If ar1.BOF = False Then
Do While Not ar1.EOF
ename = ar1(0)
ecode = ar1(1)
essn = ar1(2)
Me.Text162 = ename
Me.Text164 = ecode
Me.Text166 = essn
ar1.MoveNext
Loop
conObj.Close
End If
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No records found !", vbExclamation, "No Records"
Cancel = True
End Sub
___________________________________________________________
After running this report, only the last record will be displayed in the
report. There are 4 rows/record in the table Salary_Details. Hence I am
expecting 4 rows to be displayed in the report.
Note: I know that the above task can also be achieved by clicking the
properties of the report. and we have to select the record source as the
"salary_details" (table name/query name). But I don't want to do in this way.
Can anyone help me how to do that.
Krishnakanth VM
Software Engineer