hi everyone...
i have a record set where i store information from a query. somehow tho, s.recordcount is always 0! i saw this post:
"faeryfyrre (Programmer) Aug 21, 2003
For a start .recordCount does not give a valid total until you've progressed to the end of the RecordSet.
You have to use .MoveLast before using .recordcount to get an accurate count.
ie
.movelast
if .RecordCount > 0 then"
but if i do this it gives me an error
any ideas? my code is the follwing:
Private Sub updateBCAutC(temp As String)
Dim MaxBCAutC As Integer
MaxBCAutC = 6
Dim current As String
current = Now
Dim s As ADODB.Recordset
Set s = New ADODB.Recordset
s.Open "Select * from [BarCode] where [BarCode]='" & temp & "'", _
CodeProject.Connection, adOpenStatic
s.MoveLast
'MsgBox (s.RecordCount)
If s.RecordCount < MaxBCAutC Then
DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', '" & current & "')"
'DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', ' #Now# ')"
'DoCmd.RunSQL "select Min(LastUpdated) from BarCode"
Else
DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', '" & current & "')"
DoCmd.RunSQL "Delete from BarCode where LastUpdated=(SELECT Min(LastUpdated) AS LastUpdate FROM BarCode)"
End If
End Sub
The problem is that the recordcount is always zero! Thanks everyone
drew
i have a record set where i store information from a query. somehow tho, s.recordcount is always 0! i saw this post:
"faeryfyrre (Programmer) Aug 21, 2003
For a start .recordCount does not give a valid total until you've progressed to the end of the RecordSet.
You have to use .MoveLast before using .recordcount to get an accurate count.
ie
.movelast
if .RecordCount > 0 then"
but if i do this it gives me an error
any ideas? my code is the follwing:
Private Sub updateBCAutC(temp As String)
Dim MaxBCAutC As Integer
MaxBCAutC = 6
Dim current As String
current = Now
Dim s As ADODB.Recordset
Set s = New ADODB.Recordset
s.Open "Select * from [BarCode] where [BarCode]='" & temp & "'", _
CodeProject.Connection, adOpenStatic
s.MoveLast
'MsgBox (s.RecordCount)
If s.RecordCount < MaxBCAutC Then
DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', '" & current & "')"
'DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', ' #Now# ')"
'DoCmd.RunSQL "select Min(LastUpdated) from BarCode"
Else
DoCmd.RunSQL "INSERT INTO BarCode (BarCode, LastUpdated) VALUES ('" & temp & "', '" & current & "')"
DoCmd.RunSQL "Delete from BarCode where LastUpdated=(SELECT Min(LastUpdated) AS LastUpdate FROM BarCode)"
End If
End Sub
The problem is that the recordcount is always zero! Thanks everyone
drew