问题
I have a 2010 MS Access Application that ran fine until importing into MS Access 2013. Now all the data entry forms show #Error
in most columns of a previous record when inserting a new record. The Forms use ADODB.Recordsets. The #Error
persists until clicking on each field where it reverts to original data.
Before Vendor Update of a New Record
RowID Vendor Ticket
1 DUFFERIN 12345
2 LAFARGE 54321
3 MILTON
After Vendor Update
RowID Vendor Ticket
1 DUFFERIN 12345
3 #ERROR #ERROR
3 MILTON 123
My Connection string:
ConnectADO = "Data Provider=SQLOLEDB.1" & _
";Data Source=" & TMServerName & _
";Initial Catalog=" & TMDatabaseName & _
";Persist Security Info=False " & _
";user id=" & TMUserName & _
";password=" & TMPassword
Cn.Provider = "MSDataShape"
Cn.CommandTimeout = 120
Cn.ConnectionString = ConnectADO
Cn.Open
My Cursor Set-up
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.CursorLocation = adUseClient
rs.LockType = LockType
rs.ActiveConnection = Cn
rs.Open Sql
回答1:
I finally figured this out.
If the ADO Active Connection is open when the forms insert occurs, the #Error
behavior occurs. If the connection is closed everything is good. Inserts and updates still happen. Therefore, close the connection as soon as possible. I did it like this (the Cnn.RecordsetOpen
function is custom and has a connection.open
statement in it before the ADODB recordset open statement).
'FORM LOAD EVENT
Sub load
On Error Goto Standard_Err
Dim TSQL As String
Set Me.Recordset = Cnn.RecordsetOpen(SQL)
Standard_Exit:
Cnn.connection.close
Exit Sub
Standard_Err:
Msgbox err.description
Resume Standard_Exit
End sub
来源:https://stackoverflow.com/questions/44030063/data-entry-forms-show-error-in-most-columns-of-a-previous-record