I have a form that is used to set user security. The form is not directly link to, but gets its data from a table. The form allows me to click a check box and it then updates the table with the new information. It works, but I get an error after every other change. I've tried several things, but I set this back to the original code.
Error:
Error:
The data has been changed.
Another user edited this record and saved the changes before you attempted to save your changes.
Re-edit the record.
Code:
Dim Con As ADODB.Connection
Dim rsTable As ADODB.Recordset
Dim strSQL As String
Option Compare Database
Option Explicit
Private Sub Form_Current()
SetupGroups
End Sub
Private Sub Form_Open(Cancel As Integer)
Set Con = CurrentProject.Connection
Set rsTable = New ADODB.Recordset
strSQL = ""
strSQL = strSQL & "Select *"
strSQL = strSQL & " From user_tbl;"
rsTable.Open strSQL, Con, adOpenDynamic, adLockOptimistic
sites_fsbar.Max = rsTable.Fields.Count - 1
End Sub
Private Function SetupGroups()
Dim Count As Long
Dim Count2 As Long
Dim Current As Long
Current = sites_fsbar.Value
With rsTable
.MoveFirst
Do While .EOF <> True
For Count = 1 To 6
If (Count + (Current - 1)) < .Fields.Count Then
Me.Controls("site" & Count & "_lbl").Caption = .Fields.Item(Count + (Current - 1)).Name
Me.Controls(!UserName & "_" & Count).Value = .Fields.Item(Count + (Current - 1)).Value
Me.Controls("site" & Count & "_lbl").Visible = True
Me.Controls(!UserName & "_" & Count).Enabled = True
Else
Me.Controls("site" & Count & "_lbl").Visible = False
Me.Controls(!UserName & "_" & Count).Enabled = False
End If
Next Count
.MoveNext
Loop
End With
End Function
Private Sub sites_fsbar_Change()
SetupGroups
End Sub
Private Sub UpdateTable()
Dim Count As Long
Dim Count2 As Long
Dim Current As Long
With rsTable
.MoveFirst
Do While .EOF <> True
For Count = 1 To 6
.Fields.Item(Me.Controls("site" & Count & "_lbl").Caption).Value = Me.Controls(!UserName & "_" & Count).Value
Next Count
.Update
.MoveNext
Loop
End With
End Sub