I have an Access 2003 database that I have split into front/back ends. The front end is copied down to the users' hard drive, so everyone has their own copy. In the front end, I have a VBA function that updates a table on the backend. The backend table that I am updating has year-to-date hours for employees, and each copy of the front end deals with different Regions, so everyone is updating a different set of employees. The problem is that when two front ends are trying to update the back end at the same time, I get the dreaded 'Unrecognized Database Format' error. After getting the error in one front end, I can halt processing on it, and the other front end will keep updating just fine. I am using ADO with pessimistic locking. Any ideas on how to prevent this?
Here is the code:
Private Sub UpdateYTD(ByRef rs As Recordset, firstDay As Date)
Dim rsYTD As New Recordset
Dim strSQL As String
On Error GoTo ErrorHandler
strSQL = "Select * from tblYTDHours where social = '" & rs.Fields("social").Value & "'"
rsYTD.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockPessimistic
If Not rsYTD.EOF Then
'update YTDHours in tblMaster
rs.Fields("YTDHours") = rsYTD.Fields("YTDHours")
rs.Update
'don't increment the YTDHours in tblYTDHours if the processing date isn't larger
'than the lastIncrementMonth in tblYTDHours.
If DatePart("m", firstDay) > rsYTD.Fields("LastIncrementMonth") Then
rsYTD.Fields("YTDHours") = rsYTD.Fields("YTDHours") + rs.Fields("TotalPenHours")
rsYTD.Fields("LastIncrementMonth") = DatePart("m", firstDay)
rsYTD.Update
'update the YT in tblMaster
rs.Fields("YTDHours") = rsYTD.Fields("YTDHours")
rs.Update
End If
Else
'if a record doesn't exist for the social in tblYTDHours,add it
rsYTD.AddNew
rsYTD.Fields("Social") = rs.Fields("Social").Value
rsYTD.Fields("YTDHours") = rs.Fields("TotalPenHours").Value
rsYTD.Fields("LastIncrementMonth") = DatePart("m", firstDay)
rsYTD.Update
'since no record existed in YTDHours, just use the total hours for the month
'as YTD hours
rs.Fields("YTDHours") = rs.Fields("TotalPenHours")
rs.Update
End If
ExitHere:
On Error Resume Next
rsYTD.Close
Set rsYTD = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.description, vbOKOnly, "UPdateYTD error # " & Err.Number
Resume ExitHere
End Sub
Phil
Here is the code:
Private Sub UpdateYTD(ByRef rs As Recordset, firstDay As Date)
Dim rsYTD As New Recordset
Dim strSQL As String
On Error GoTo ErrorHandler
strSQL = "Select * from tblYTDHours where social = '" & rs.Fields("social").Value & "'"
rsYTD.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockPessimistic
If Not rsYTD.EOF Then
'update YTDHours in tblMaster
rs.Fields("YTDHours") = rsYTD.Fields("YTDHours")
rs.Update
'don't increment the YTDHours in tblYTDHours if the processing date isn't larger
'than the lastIncrementMonth in tblYTDHours.
If DatePart("m", firstDay) > rsYTD.Fields("LastIncrementMonth") Then
rsYTD.Fields("YTDHours") = rsYTD.Fields("YTDHours") + rs.Fields("TotalPenHours")
rsYTD.Fields("LastIncrementMonth") = DatePart("m", firstDay)
rsYTD.Update
'update the YT in tblMaster
rs.Fields("YTDHours") = rsYTD.Fields("YTDHours")
rs.Update
End If
Else
'if a record doesn't exist for the social in tblYTDHours,add it
rsYTD.AddNew
rsYTD.Fields("Social") = rs.Fields("Social").Value
rsYTD.Fields("YTDHours") = rs.Fields("TotalPenHours").Value
rsYTD.Fields("LastIncrementMonth") = DatePart("m", firstDay)
rsYTD.Update
'since no record existed in YTDHours, just use the total hours for the month
'as YTD hours
rs.Fields("YTDHours") = rs.Fields("TotalPenHours")
rs.Update
End If
ExitHere:
On Error Resume Next
rsYTD.Close
Set rsYTD = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.description, vbOKOnly, "UPdateYTD error # " & Err.Number
Resume ExitHere
End Sub
Phil