T
TrickDownie
I have a table(Jobs) that I am trying update the start DateTime field
with Active values in another table(Downloads).
When I run the code I get teh Run-Time Error 3021 "Either BOF or EOF is
True, ....
****See below alternative
'UPDATE START DATES
Private Sub Command12_Click()
Dim SQLString As String
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim cmd2 As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim rst2 As New ADODB.Recordset
DoCmd.SetWarnings False
Set cnn = CurrentProject.Connection
Set cmd.ActiveConnection = cnn
Set cmd2.ActiveConnection = cnn
SQLString = "SELECT * "
SQLString = SQLString & "FROM jobs "
SQLString = SQLString & "WHERE
(((jobs.active_jobs_msglog_crtdt) Is Null));"
' MsgBox (SQLString)
cmd.CommandText = SQLString
rst.CursorLocation = adUseClient
rst.Open cmd, , adOpenKeyset, adLockOptimistic
If rst.RecordCount > 0 Then
Do While Not rst.EOF
SQLString = "SELECT downloads.Branch_Number, downloads.msglog_text,
downloads.item_id, Min(downloads.msglog_crtdt) AS MinOfmsglog_crtdt "
SQLString = SQLString & "FROM downloads "
SQLString = SQLString & "GROUP BY downloads.Branch_Number,
downloads.msglog_text, downloads.item_id "
SQLString = SQLString & "HAVING (((downloads.Branch_Number)= " &
rst!Branch_Number & ") AND ((downloads.msglog_text) Like " & """" & "*"
& "active" & "*" & """" & ") AND ((downloads.item_id)= " & rst!item_id
& "));"
******IF I REMOVED THE ((downloads.msglog_text) Like " & """" & "*" &
active & "*" & """" & ") FROM THIS SQLStirng I get the 4 records from
the downloads table[Active, Launched, Waiting, Completed] when I only
want to rst2 the Active record
cmd2.CommandText = SQLString
rst2.CursorLocation = adUseClient
rst2.Open cmd2, , adOpenKeyset, adLockOptimistic
MsgBox (rst2.GetString)
If rst2.RecordCount > 0 Then
SQLString = "UPDATE jobs SET
jobs.active_jobs_msglog_crtdt = (" & rst2!MinOfmsglog_crtdt & ") "
SQLString = SQLString & "WHERE (((jobs.qrt)
= " & rst!qrt & ") AND ((jobs.year) = " & rst!Year & ") AND
((jobs.Branch_Number) = " & rst!Branch_Number & ") AND ((jobs.item_id)
= " & rst!item_id & "));"
DoCmd.RunSQL (SQLString)
End If
rst.MoveNext
rst2.Close
Loop
End If
DoCmd.SetWarnings True
End Sub
with Active values in another table(Downloads).
When I run the code I get teh Run-Time Error 3021 "Either BOF or EOF is
True, ....
****See below alternative
'UPDATE START DATES
Private Sub Command12_Click()
Dim SQLString As String
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim cmd2 As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim rst2 As New ADODB.Recordset
DoCmd.SetWarnings False
Set cnn = CurrentProject.Connection
Set cmd.ActiveConnection = cnn
Set cmd2.ActiveConnection = cnn
SQLString = "SELECT * "
SQLString = SQLString & "FROM jobs "
SQLString = SQLString & "WHERE
(((jobs.active_jobs_msglog_crtdt) Is Null));"
' MsgBox (SQLString)
cmd.CommandText = SQLString
rst.CursorLocation = adUseClient
rst.Open cmd, , adOpenKeyset, adLockOptimistic
If rst.RecordCount > 0 Then
Do While Not rst.EOF
SQLString = "SELECT downloads.Branch_Number, downloads.msglog_text,
downloads.item_id, Min(downloads.msglog_crtdt) AS MinOfmsglog_crtdt "
SQLString = SQLString & "FROM downloads "
SQLString = SQLString & "GROUP BY downloads.Branch_Number,
downloads.msglog_text, downloads.item_id "
SQLString = SQLString & "HAVING (((downloads.Branch_Number)= " &
rst!Branch_Number & ") AND ((downloads.msglog_text) Like " & """" & "*"
& "active" & "*" & """" & ") AND ((downloads.item_id)= " & rst!item_id
& "));"
******IF I REMOVED THE ((downloads.msglog_text) Like " & """" & "*" &
active & "*" & """" & ") FROM THIS SQLStirng I get the 4 records from
the downloads table[Active, Launched, Waiting, Completed] when I only
want to rst2 the Active record
cmd2.CommandText = SQLString
rst2.CursorLocation = adUseClient
rst2.Open cmd2, , adOpenKeyset, adLockOptimistic
MsgBox (rst2.GetString)
If rst2.RecordCount > 0 Then
SQLString = "UPDATE jobs SET
jobs.active_jobs_msglog_crtdt = (" & rst2!MinOfmsglog_crtdt & ") "
SQLString = SQLString & "WHERE (((jobs.qrt)
= " & rst!qrt & ") AND ((jobs.year) = " & rst!Year & ") AND
((jobs.Branch_Number) = " & rst!Branch_Number & ") AND ((jobs.item_id)
= " & rst!item_id & "));"
DoCmd.RunSQL (SQLString)
End If
rst.MoveNext
rst2.Close
Loop
End If
DoCmd.SetWarnings True
End Sub