cmd.CommandText = "SELECT  distinct GLMAST.fglhead,MAINFILE.facno,max(MAINTRAN.fdate) as fdate ,max(MAINTRAN.fbalance) as fbalance  FROM MAINTRAN INNER JOIN MAINFILE ON  MAINFILE.facno like MAINTRAN.facno INNER JOIN MASTERID ON  MAINFILE.fmasterno like MASTERID.fmasterid  INNER JOIN  GLMAST ON GLMAST.fglcode like  LEFT(MAINFILE.facno,9) and   GLMAST.fglhead = '" & ComboBox2.Text & "' and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _                                           "where MAINTRAN.fbankcode='" & "010" & "'" & _                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _                                          "and MAINTRAN.fbranchcode='" & "01" & "' group by MAINFILE.facno,GLMAST.fglhead "
 Collapse | Copy Code  
With cmd
dr = .ExecuteReader
End With
 
If dr.HasRows = True Then
Do While dr.Read
presentdaybal = dr!fbalance
Loop
dr.Close()