如果您在刷新SharePoint列表时遇到Access用户窗体出现错误的问题,请检查以下代码是否适用于您的情况:
Private Sub Form_Load()
'Connect to SharePoint site
Dim adoConn As ADODB.Connection
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=http://sharepoint_site_address/;LIST={GUID_of_list}"
'Create query
Dim strSQL As String
strSQL = "SELECT * FROM [List Name]"
'Open recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open strSQL, adoConn, adOpenKeyset, adLockOptimistic
'Bind recordset to form
Set Me.Recordset = rst
rst.Close
adoConn.Close
End Sub
在Access中刷新SharePoint列表时,请确保数据库缓存已清空。您可以通过将以下代码添加到您的按钮单击事件中来实现:
Private Sub cmdRefresh_Click()
Dim db As DAO.Database
Set db = CurrentDb
'Clear database cache
db.QueryDefs.Refresh
Me.Requery
End Sub
这应该解决在刷新SharePoint列表时出现错误的问题。