I had a query that was working properly just using the grid. I had to add a extra feature in so I needed to create an IF statement so I brought the query into VBA as an SQL statement. I may have more than one problem with how this is written, but the point I can’t get by is in the Else Where statement it gives me a compile/syntax error and highlights RN on the First line of the Where clause. Since I have a very basic understanding of SQL I would appreciate any and all assistance.
The situation is this I have four main credential groupings RN, LPN, Assistant, UC. I now need to account for Agency RNs. Data is entered as Credentials which is the RN, LPN, etc. Status is things like parttime, inhouse agency, agency, or fulltime etc. So if someone’s status is Agency then the ReguiredAgencyRN should be selected. But if they are not agency the report should show the appropriate credentials.
If Reports.rptOrientationChecklist.txtStatus.Value = “Agency” Then
‘ SQL to obtain records for agency nurses
strSQL = ” SELECT tblComponents.Name, tblComponents.PresentationType, ” & _
“tblComponentDept.RequiredAgencyRN, tblComponentDept.Department” & _
“FROM tblComponents INNER JOIN tblComponentDept ” & _
“ON tblComponents.ComponentID = tblComponentDept.ComponentID ” & _
“WHERE (((tblComponentDept.RequiredAgencyRN)=-1)” & strWhere1
Else
‘ SQL to obtain records for regular staff
strSQL = ” SELECT tblComponents.Name, tblComponents.PresentationType, ” & _
“tblComponentDept.RequiredRN, tblComponentDept.RequiredLPN, ” & _
“tblComponentDept.RequiredAide, tblComponentDept.RequiredUC, ” & _
“tblComponentDept.Department” & _
“FROM tblComponents INNER JOIN tblComponentDept ” & _
“ON tblComponents.ComponentID = tblComponentDept.ComponentID ” & _
“WHERE (((tblComponentDept.RequiredRN) Like IIf([Reports]![rptOrientationChecklist]![txtCredential]=”RN”,”-1″,”*”))” & _
“AND ((tblComponentDept.RequiredLPN) Like IIf([Reports]![rptOrientationChecklist]![txtCredential]=”LPN”,”-1″,”*”))” & _
“AND ((tblComponentDept.RequiredAide) Like IIf([Reports]![rptOrientationChecklist]![txtCredential]=”Nursing Assistant”,”-1″,”*”))” & _
“AND ((tblComponentDept.RequiredUC) Like IIf([Reports]![rptOrientationChecklist]![txtCredential]=”Unit Clerk”,”-1″,”*”)))” & strWhere1
End If
Do I need this DoCmd line. I think Hans said I only needed it when creating tables. But I wouldn’t bank anything on my memory.
‘ Execute it
DoCmd.RunSQL strSQL
stDocName = “rptOrientationChecklist”
DoCmd.OpenReport stDocName, acPreview, , strWhere1
PS this code is associated with the click event of a button. Should it be associated with the on open even of the form?
Thank you for your help.
Fay