Hi,
My split database is working on One Access for Developer (me) and Access runtime for users.
Problem is described here:
https://support.microsoft.com/en-us/...ted-editing-it
My code is working like that:
Code:
Private Sub Button_Run_Click()
Dim LoginName As String
Dim strSQL As String
Dim LookLast As String
Dim Digits As Long
Dim NewOne As String
Dim response As String
Dim SqlString As String
Dim ActualYear As String
Dim DokumentName As String
Dim i As Byte
Dim counter As Byte
Dim Obowiazek As String
Dim BoolListbox As Boolean
Dim rstBraki As Recordset
DoCmd.SetWarnings False
LoginName = TempVars("Username")
Me.Requery
On Error Resume Next
LookLast = DLast("[Numer_zgłoszenia]", "Qry_Numbers", "[Login] ='" & LoginName & "'")
If Err.Number <> 0 Then
NewOne = LoginName & "_" & Year(Date) & "_1"
Else
NewOne = GetDigits(LookLast)
End If
On Error GoTo 0
For i = 0 To ListBox_Doc.ListCount
If ListBox_Doc.Selected(i) = True Then
counter = counter + 1
DokumentName = ListBox_Doc.Column(0, i)
Obowiazek = ListBox_Doc.Column(1, i)
If Obowiazek = "TAK" Then
BoolListbox = True
Else
BoolListbox = False
End If
SqlString = "INSERT INTO tbl_Braki([Numer_zgłoszenia], [Zleceniodawca_nr], [Zleceniodawca_nazwa], [Nr_SAP], [Imię_i_Nazwisko], [Dokument], [Czy_obowiązkowy], [Data_Wysłania], [Data_Zwrotu], [Uwagi], [Login]) " & _
"VALUES ('" & NewOne & "', '" & Combo_Spolka.Column(1) & "', '" & Combo_Spolka.Column(0) & "', '" & Nr_SAP.Value & "', '" & Imię_i_Nazwisko.Value & "', '" & DokumentName & "', " & BoolListbox & ", '" & Data_Wysłania.Value & "', '" & Data_Zwrotu.Value & "', '" & Uwagi.Value & "', '" & LoginName & "');"
DoCmd.RunSQL SqlString
ListBox_Doc.Selected(i) = False
End If
Next i
If counter = 0 Then
MsgBox "nie wybrano żadnego dokumentu, rekord NIE został dodany"
End If
'''rstBraki.Update
Application.Echo True
End Sub
I have listbox with 25 documents where user can choose multiple documents per each Client. This code is inserting this documents for number of documents choosen by user.
So If user checks Document 1 , Document 2 and Document 3 on listbox this code will add 3 new records into main table.
Problem is where two users are trying to run macro from front -end at the same time. The problem: "This record has been changed by another user since you started editing it" is occuring...
I have tried to use:
Code:
DoCmd.GoToRecord , , acNewRec
and
Code:
''Set rstBraki = CurrentDb.OpenRecordset("tbl_Braki")
rstBraki.AddNew
''code here
rstBraki.update
but these methods failed...
How can I avoid this error using code?
Maybe when error is occurning by second user the macro will loop for 2 secunds to avoid it?
It is very serious problem for my database,
please help
Jacek Antek