Dim datcmd1 As ADODB.Command
Set datcmd1 = New ADODB.Command
Set datcmd1.activeConnection = cnn1
datcmd1.CommandText = "SELECT Sum(If(IsNull(paid),0,paid) + If(IsNull(provided),0,If(paid>0,0,provided))) AS totalpaid, Billing.method AS typepaid, Billing.date, Visits.exam9 FROM Visits RIGHT JOIN Billing ON Visits.prim_key = Billing.visit_num GROUP BY Billing.date, Visits.exam9, Billing.method"
datcmd1.CommandType = adCmdText