I am using Vb6. I am using data report in my program I have it working but when I print it is printing all the records in the database. I am having troubles with it printing a single record. with the help of dataenvironment. If there is anyone out there that has had this same problem and know how to correct it. I would really appreciate it thank you for your time
I would suggest to work without data environment.
Include just the datareport
Now design your data report
Place the textboxes on the Detail section
Name the textboxes exactly the same you have named the data
eg you have a table name emp which consists of
empno,empname,empadd,empsalary,empjoindate
Now in the datafield of the textboxes name the same as above.
Now your question of printing a single record
You certainly must have at least one of the datafield which contains unique data
Code it as below
Dim db_file As String
Dim Mycon1 As New ADODB.Connection
Dim m1 As New ADODB.Recordset
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
db_file = db_file & "emp.mdb"
' Open a connection.
Mycon1.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
Me.Refresh
Mycon1.Open
Set m1 = Mycon1.Execute("select empno,empname,empadd,empsalary,empjoindate where empno='" & Text1.Text & "'", , adCmdText)
' Here Text1.Text will be the empno . If it is only number then remove the single quotes after empno and &(ampersand) also do not forget to include val before Text1.Text
' Connect the Recordset to the DataReport.
Set DataReport1.DataSource = m1
DataReport1.WindowState = vbMaximized
DataReport1.Show vbModal
DataReport1.Caption = "Employee Details"
m1.Close
Mycon1.Close
Set Mycon1 = Nothing
End If
Try it out and let me know