Dear Team,

I have a crystal report in my vb application, which is reflecting all the records on the report, even though I have a SQL query to retrieve only a specific record, But report keep displaying all the records in the table. below is my code, guide me where exactly I am going wrong.

Frm_SCHS_Renewal
Code:
Private Sub cmd_save_Click()
//few lines of code for validation and saving data into table

If MsgBox("Do you want to print the DataFlow Group & SCHS Renewal Form ?", vbYesNo, "Print Form") = vbYes Then

Form2.Show

Else
Exit Sub
End If

End Sub
Form2 is containing CRViewer

Form code is as below.

Code:
Dim Report As New Rpt_SCHS_RenewalDsr

Private Sub Form_Load()
GetLastID
Dim temp As Integer
temp = lbl_id.Caption
Screen.MousePointer = vbHourglass

SQL = " SELECT id, first_name, mid_name, last_name, date_of_birth, passport_no, email_id, mob_no, app_type, schs_acc_no, old_ref_no, md, phd, dhs, mem, fellowship, specialist, certificate, bachelor, master, diploma, " _
    & " ed_to_varify, major_subject, university_name, college_name, date_issued_certificate, others, ec_to_varify, employer_name, position, start_date, end_date, hl_to_varify, issuing_aut_name, license_attended, " _
    & " license_issue_date From dbo.tbl_schs_renewal WHERE dbo.tbl_schs_renewal.id='" & temp & "' "
connectDB
Debug.Print RS.Fields("id") 'just tried to see if query is returning correct row from table and it does return correct row of data.

With Report
        .Database.SetDataSource RS
        .PaperOrientation = 1
        .PaperSize = 2
        .DiscardSavedData
End With

With CRViewer1
        .ReportSource = Report
        .ViewReport
        .Zoom (2)
End With
    WindowState = 2
    Screen.MousePointer = vbDefault


End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth

End Sub

Public Sub GetLastID()
SQL = "Select MAX(id) from tbl_schs_renewal "
connectDB
With RS
    lbl_id.Caption = RS.GetString
End With
connClose
End Sub
I tried getting the result of query in immediate window and the result returned from query is absolutely correct, I mean it is reflecting MAX(id) and related fields from table.

I am not sure why the SetDatasource RS command is not working in my case.

Please guide.