View Full Version : printing a filtered table/database


smiler44
01-03-2009, 05:52 AM
I'm using Vb version 5, a dbgrid control and a data control. I have created my Access database via the Add In's Visual Data Manager.

I have filtered the Access table to show just the records I want but can not work out the code to print the filtered table nor can I work out the code to print the whole of the table. The code I'm using to do the filtering is below

Any ideas?

Thanks smiler44

Private Sub cmdfind_Click()
Dim x 'declares x for message box
Dim mystring
If Text5.Text = "" Then
MsgBox ("Nothing to find")
Exit Sub
Else
mystring = Text5.Text
End If
'finds by Fault Report Number
Data1.RecordSource = "select * from [Exchange Visits] where [Fault Report Number] like '" + mystring + "'order by Date"
Data1.Refresh
If Data1.Recordset.EOF Then
' finds by exch
Data1.RecordSource = "select * from [Exchange Visits] where [Exchange] like '" + mystring + "'order by Date"
Data1.Refresh
End If
'if only 1 record asks if you want to see file
If Data1.Recordset.RecordCount = 1 Then
x = MsgBox("Would you like to see the file for this report?", 36, "confirm")
If x = 6 Then ' y
Call DBGrid1_DblClick
Exit Sub
End If
End If

If Data1.Recordset.EOF Then
MsgBox ("Sorry I can not find what you are looking for.")
Data1.RecordSource = " select * from [Exchange Visits] where Date like'" + ("*") + "'order by Date"
Data1.Refresh
End If
End Sub