Hi
I have built a query in the design view in Access and the query works but when moving it into VBA it doesn't!
I have a form that logs an error and the user can select two areas and two teams if they want. (Second is optional)
When they log it I want to retrieve the email from tblUsers of the team manager.
When using VBA it only returns 1 email when I know the options selected should return two and as I said it does in the Query Designer.
Here is the code: (FYI I know DAO is outdated I will be moving to ADO shortly)
Public Sub SendBreachEmail()
Dim LoggedArea1 As String
Dim LoggedArea2 As String
Dim LoggedTeam1 As String
Dim LoggedTeam2 As String
LoggedArea1 = Form_frmLogBreach.cboAreaCaused1
LoggedArea2 = Nz(Form_frmLogBreach.cboAreaCaused2, "")
LoggedTeam1 = Form_frmLogBreach.cboTeamCaused1
LoggedTeam2 = Nz(Form_frmLogBreach.cboTeamCaused2, "")
Dim sql As String
Dim rec As DAO.Recordset
If Form_frmLogBreach.cboAreaCaused2 = "" Then
sql = "SELECT tblUsers.Email FROM tblUsers WHERE (((tblUsers.UserGrade)='Manager') AND ((tblUsers.Department)='" & LoggedArea1 & "') AND ((tblUsers.Team)='" & LoggedTeam1 & "'"
Else
sql = "SELECT tblUsers.Email FROM tblUsers WHERE (((tblUsers.UserGrade)='Manager') AND ((tblUsers.Department)='" & LoggedArea1 & "') AND ((tblUsers.Team)='" & LoggedTeam1 & "')) OR (((tblUsers.Department)='" & LoggedArea2 & "') AND ((tblUsers.Team)='" & LoggedTeam2 & "'));"
End If
Set rec = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
MsgBox (rec.RecordCount)
rec.Close
Set rec = Nothing
End Sub
Any help would be greatly appreciated.
Thanks
Carl
I have built a query in the design view in Access and the query works but when moving it into VBA it doesn't!
I have a form that logs an error and the user can select two areas and two teams if they want. (Second is optional)
When they log it I want to retrieve the email from tblUsers of the team manager.
When using VBA it only returns 1 email when I know the options selected should return two and as I said it does in the Query Designer.
Here is the code: (FYI I know DAO is outdated I will be moving to ADO shortly)
Public Sub SendBreachEmail()
Dim LoggedArea1 As String
Dim LoggedArea2 As String
Dim LoggedTeam1 As String
Dim LoggedTeam2 As String
LoggedArea1 = Form_frmLogBreach.cboAreaCaused1
LoggedArea2 = Nz(Form_frmLogBreach.cboAreaCaused2, "")
LoggedTeam1 = Form_frmLogBreach.cboTeamCaused1
LoggedTeam2 = Nz(Form_frmLogBreach.cboTeamCaused2, "")
Dim sql As String
Dim rec As DAO.Recordset
If Form_frmLogBreach.cboAreaCaused2 = "" Then
sql = "SELECT tblUsers.Email FROM tblUsers WHERE (((tblUsers.UserGrade)='Manager') AND ((tblUsers.Department)='" & LoggedArea1 & "') AND ((tblUsers.Team)='" & LoggedTeam1 & "'"
Else
sql = "SELECT tblUsers.Email FROM tblUsers WHERE (((tblUsers.UserGrade)='Manager') AND ((tblUsers.Department)='" & LoggedArea1 & "') AND ((tblUsers.Team)='" & LoggedTeam1 & "')) OR (((tblUsers.Department)='" & LoggedArea2 & "') AND ((tblUsers.Team)='" & LoggedTeam2 & "'));"
End If
Set rec = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
MsgBox (rec.RecordCount)
rec.Close
Set rec = Nothing
End Sub
Any help would be greatly appreciated.
Thanks
Carl