1
votes

I have an Access file that sits in a folder. That the folder is linked to the company's server. Which means that the Access file can be accessed through every computer in the company.

The problem that i have is that, while i am able to log into the access file from one computer, when i try to log into the same file from a different computer, the error "Error 3021, No Current Record" appears.

This is my code.

'Daily Material Record Code
sql = "select max(Date_Recorded) from Daily_Material"
Set rst = CurrentDb.OpenRecordset(sql)

If (rst.EOF Or IsNull(rst.Fields(0))) Then
        lastdate = "01/01/1990"
        LastYear = 1990
        LastID = 0
Else
        maxlastdate = rst.Fields(0)
        lastdate = DateValue(rst.Fields(0))
        lasttime = TimeValue(rst.Fields(0))
        LastYear = Year(rst.Fields(0))
        'LastID = Val(Mid(rst!ID, 6))
        sql = "select ID from Daily_Material where Date_Recorded = #" & maxlastdate & "# "
        Set rst = CurrentDb.OpenRecordset(sql)
        LastID = CStr(Val(Mid(rst.Fields(0), 6))) <---- This is where the error happens

End If

That right there just confused me. Shouldn't there not be an error since i log into the same file from the server? This error only happens when i log into the access file in a different computer.

Does anyone know why this happens and how i can solve this?

1
Did you read through the other posts here concerning this same error to see if they help? Search access error 3021. - Ken White
Sorry but i already tried, i believe that my issue is quite bizzare, it's my first time encountering something like this. I have edited my question if it helps describe my problem better. @KenWhite - Hamizan
Your edit does not indicate any effort to use any of the two dozen existing answers to try and find a solution. - Ken White

1 Answers

0
votes

You must check for no records found, and use your variables.

Also, only one call of the recordset is needed:

sql = "select top 1 ID, Date_Recorded from Daily_Material order by Date_Recorded desc"
Set rst = CurrentDb.OpenRecordset(sql)

lastdate = #01/01/1990#
LastYear = 1990
LastID = 0

If rst.RecordCount > 0 Then
    If Not IsNull(rst.Fields(1).Value) Then
        maxlastdate = rst.Fields(1).Value
        lastdate = DateValue(maxlastdate)
        lasttime = TimeValue(maxlastdate)
        LastYear = Year(maxlastdate)
        LastID = CStr(Val(Mid(rst.Fields(0).Value, 6))) 
    End If
End If
rst.Close