How To Print data with selected rekord from DBGrid

Hi, All Guru member,
I have problem to print my data.

All record in database i show at DBGrid.

That say, my option, to show the record only selected item by name.
and the record show in DBGrid.

so, i have problem to print record (data) from DBGrid.

I've already make the data environment and data report.

Please help me...

Thanks.
[398 byte] By [TJ-Ariff] at [2007-11-20 11:06:25]
# 1 Re: How To Print data with selected rekord from DBGrid
any one can't help me ?

Please help me to solve this problem, i have 1 VB Project on hand.
My project working in 80% , just waiting for the print statment..

please help me...
TJ-Ariff at 2007-11-9 19:33:58 >
# 2 Re: How To Print data with selected rekord from DBGrid
Hi TJ!!
No one reply... quite weird... Maybe you should elaborate a little bit more about what you want ? Do you only want to know how to print ? or do you already know how to print, but you only want to know how to select only a spesific record ?
for me, i only use crystal report for printing, even the CR that i used is only the basic function, very very basic. so i dont think that i am the right person to address your problem, there are certainly many people who are more capable than me.
Hope the best for you
Dock at 2007-11-9 19:34:58 >
# 3 Re: How To Print data with selected rekord from DBGrid
Hi dock..
my problem is, in my program, have a 3 selection option, (1) Print All (2)Print by name (3)Print By month.
so, options 1 and 3 no problem..
but option no 2, i can view in DBGrid only but can't print .

so, can you help me or any one, what coding i must use to print the spesific record.
Thanks..
TJ-Ariff at 2007-11-9 19:36:03 >
# 4 Re: How To Print data with selected rekord from DBGrid
Can you post the code u use for Print By Month option ? dont forget to use the CODE and /CODE tags. Thx
Dock at 2007-11-9 19:36:57 >
# 5 Re: How To Print data with selected rekord from DBGrid
ok, this is my coding ...
for Print By month, i create 12 Data Report...

Private Sub cmdPrint_Click()
If OptAll.Value = True Then GoTo PrnAll
If OptName.Value = True Then GoTo PrnByName
If OptMonth.Value = True Then GoTo PrnByMonth

PrnAll:
PrnAll.Show
GoTo Finish

PrnByName:
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db & "\"
db_file = db_file & "ERekod.mdb"

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 NoPekerja, Nama, Jabatan, Tarikh, MasaKeluar, MasaMasuk, JumlahMasa, Diluluskan, Tujuan where Nama ='" & txtByName & "'") ', , adCmdText)

Set PrnName.DataSource = m1
PrnName.WindowState = vbMaximized
PrnName.Show vbModal
PrnName.Caption = "Pra Cetak Mengikut Nama"
m1.Close
'Mycon1 = Nothing
'End If

GoTo Finish

PrnByMonth:
Dim itemdata As String
itemdata = cboByMonth.Text

If itemdata = "January" Then PrnJan.Show
If itemdata = "February" Then PrnFeb.Show
If itemdata = "March" Then PrnMar.Show
If itemdata = "April" Then PrnApr.Show
If itemdata = "May" Then PrnMay.Show
If itemdata = "June" Then PrnJun.Show
If itemdata = "July" Then PrnJul.Show
If itemdata = "August" Then PrnAug.Show
If itemdata = "September" Then PrnSep.Show
If itemdata = "October" Then PrnOct.Show
If itemdata = "November" Then PrnNov.Show
If itemdata = "December" Then PrnDec.Show

Finish:
cmdPrint.Enabled = False
End Sub

Thanks for your help...
TJ-Ariff at 2007-11-9 19:37:59 >
# 6 Re: How To Print data with selected rekord from DBGrid
I would use control arrays for the forms.

PrnDec.PrintForm

should work. using arrays:

Prn(11).PrintForm
dglienna at 2007-11-9 19:39:04 >
# 7 Re: How To Print data with selected rekord from DBGrid
Eh, do you you use separate form to print each of the report ? if so, then why your coding should be okay, isnt it ? why you cant print ? btw, are you from malaysia ?
Dock at 2007-11-9 19:39:57 >
# 8 Re: How To Print data with selected rekord from DBGrid
Thanks for replay..
Now my program is working if i select Print All or Print By Month.
My coding, show the print preview first before printing.
But in Print By Name section, i have problem, the selected record by name show in DBGrid,
but when click print , error come out :-

Run-time error -'214721900(80040e14)

Syntax error(missing operetor)in query expression 'Tujuan WHERE nama ='Fauzi'"
_______________________________________

so can u help me to modify the coding.

To Dock,
yes i'am from Malaysia...
glad to meet u.
TJ-Ariff at 2007-11-9 19:41:00 >
# 9 Re: How To Print data with selected rekord from DBGrid
Post some code, or the project, if it's zipped and will run for others. If not, make a new program with the parts that don't work.
dglienna at 2007-11-9 19:42:03 >