Hello,
In the code below, I am trying to get a record count from a DAO recordset. The problem comes in when I attempt to get a recordcount of the recordset. The query only grabs the records that are open (determined by a yes/no field in the table) but the recordcount returns a count for every record in the table. Can anyone tell me why this is happening?
Thanks in advance
AtlasAF
USAF
In the code below, I am trying to get a record count from a DAO recordset. The problem comes in when I attempt to get a recordcount of the recordset. The query only grabs the records that are open (determined by a yes/no field in the table) but the recordcount returns a count for every record in the table. Can anyone tell me why this is happening?
Code:
Private Sub btnTTClose_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intPos As Integer
Dim msg As VbMsgBoxResult
Dim strSol As String
Dim dat As Date
Dim tim As Date
Dim strSQL As String
strSol = Forms!frmTTView!TTSolution.Value
strSQL = "SELECT tblAssignment.AEndDate, tblAssignment.AClosed " & _
"FROM tblAssignment " & _
"WHERE ((tblAssignment.AClosed)=No) AND ((tblAssignment.TTID)=" & [Forms]![frmTTView]![TTID] & ");"
dat = Date
tim = Time
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.RecordCount > 1 Then
msg = MsgBox("There are more than one technician currently assigned to this ticket. " & _
"Do you still want to close this ticket and remove thier assignments?", vbYesNoCancel, "Close Ticket")
If msg = vbNo Then
Exit Sub
ElseIf msg = vbYes Then
For intPos = 0 To rs.Fields.Count
With rs
.Edit
!AEndDate = dat & " " & tim
!AClosed = "Yes"
.Update
rs.MoveNext
End With
Next intPos
[Forms]![frmTTView]![TTCloseDate].Value = Date
DoCmd.Save
End If
ElseIf rs.RecordCount = 1 Then
With rs
.Edit
!AEndDate = dat & " " & tim
!AClosed = "Yes"
.Update
End With
[Forms]![frmTTView]![TTCloseDate].Value = Date
DoCmd.Save
ElseIf rs.RecordCount = 0 Then
[Forms]![frmTTView]![TTCloseDate].Value = Date
DoCmd.Save
End If
Set db = Nothing
Set rs = Nothing
intPos = 0
strSol = ""
strSQL = ""
End Sub
Thanks in advance
AtlasAF
USAF