how to insert a record to a report

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
 
D

Duane Hookom

Prior to putting any effort into creating an unbound report, I would like to
know your reason for "But I don't want to do in this way."

Bound reports are like eating ice cream. Unbound reports require serious
code and possibly unnecessary efforts.
 
K

Krishnakanth

The example what I have given is a sample one. Currently I am working in a
big application. It involves data's from multiple tables, manpulating those
values and has to fetch rows from another table with those outputs. That 's
why I have mentioned
"But I don't want to do in this way."
I want to do programmatically. Those task cannot be achieved by the second
method that I have mentioned.

Could you please us to get this done.

Krishnakanth VM
Software Engineer
 
D

Duane Hookom

I have no experience with code to do this. I would be stuck googling 'access
report unbound' and checking Google Groups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top