Locking Records

Dina01

Registered User.
Local time
Today, 20:25
Joined
Apr 24, 2002
Messages
87
Hello,
I have almost completed my db, but now the only thing left in my application, is that I have to lock the data.

I was testing it with my co-worker and if we are entering data in different forms, but then clicking on the OK button to save the records, well we both get the same sequential number, and the db bugs....

I have never made any db for multi-user, therefore I have no idea were to start.

My forms are all unbounds and they save only when I click on the OK button. Here is some of the code

**********************

Private Sub Btn_OK_Click()

Dim rsData As Recordset ' Set rs as recordset
Dim rsAgent As Recordset ' Set rs as recordset

'Enable errors-handling routine
On Error GoTo Err_Btn_OK_Click

Dim strMessage As String 'Declares strMessage as string
Dim message As String 'Declares message as string

' If an agent is chosen and you click on the OK button
If Not IsNull(Me.Agt1) Then

' Set the Start time of the call to be visible
Me.HrsDebut.Visible = True
' Automatically assign the current time
Me.HrsDebut = Time()
' Do not show the Finish time, since call is not finish
Me.HrsFin.Visible = False
' Do not show the Waiting Time, since call is not waiting status
Me.HrsEnAttente.Visible = False

' Stored the time
'LogHrsDebut = Me!HrsDebut


' Set "Data_tb" to be the current recordset
Set rsData = CurrentDb.OpenRecordset("Data_tb")

' Add all the following fields to the current recordset
With rsData

.AddNew
!DataID = ObtenirSequence
!Date = Me!Date
!Categorie = Me!Categorie
!Priorite = "1"
!Descriptions = Me!description
!Lieux = Me!Lieux
!Niveau = Me!Niveau
!Emplacement = Me!Emplacement
!Precision = Me!précisions
!Telephone = Me!Telephone
!NumEmployé = Me!NoEmpl
!Commentaires = Me!Commentaires
!Sexe = Me!Sexe
!Age = Me!Age
!ConscienceDescription = Me!EtatCons
!Respiration = Me!respiratoire
!Pouls = Me!Pouls
!Informations = Me!Informations
!HrsSupSecAvise = Me!HrsSupSecAvise
!HrsSurvAvise = Me!HrsSurvAvise
!HrsEntMenAvise = Me!HrsEntMenAvise
!HrsAviseInfirm = Me!HrsAviseInfirm
!HrsClientDirect = Me!HrsClientDirect
!HrsRendrePlace = Me!HrsRendrePlace
!HrsRegul = Me!HrsRegul
!HrsUrgSante = Me!HrsUrgSante
!HrsPolice = Me!HrsPolice
!HrsPompier = Me!HrsPompier
!HrsRecuCall = Me!HrsRecu
!HrsDebutCall = Me!HrsDebut
!IncidentIdicatif = Me!IncidentIdicatif
!IncidentSeq = Me!IncidentSeq
!HospitalierDescription = Me!CentreHosp
!Evenement = "URGENCE MÉDICALE"
!Code = "1"
!DateLog = Me!DateLog
!userId = Me!userId
!TimeLog = Me!TimeLog
' !CallTime = Me!txtCallTime

.Update
.Close
End With

' Set "Agent_tb" to be the current recordset
Set rsAgent = CurrentDb.OpenRecordset("Agent_tb")

With rsAgent
.AddNew
!DataID = ObtenirSequenceAGT
!Date = Date
!HrsRecu = Me!HrsRecu
!HrsDebut = Time()
!HrsFin = Me!HrsFin
!Agent = Me.Agt1
!Code = "1"

.Update
.Close
End With


'Check if control "agent 2" is empty, if the answer is yes, then do the procedure below
If Not IsNull([Agt2]) Then

' Add all the following fields to the current recordset for the second agt
Set rsAgent = CurrentDb.OpenRecordset("Agent_tb")
With rsAgent
.AddNew
!DataID = ObtenirSequenceAGTsame
!Date = Date
!HrsRecu = Me!HrsRecu
!HrsDebut = Time()
!HrsFin = Me!HrsFin
!Agent = Me.Agt2
!Code = "1"

.Update
.Close

etc.............


And the sequential numbers come from a module
**********

Function ObtenirSequence() As Long

'Fonction servant a définir le numéro séquentiel relié à l'événement dans la table data_tb, selon la date du jour,
'repart a zéro a tous les jours

Dim sSql As String
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb

Set rstTemp = db.OpenRecordset("Select max([dataID]) from data_tb Where [date] = #" & Format(Now, "yyyy-mm-dd") & "#")
ObtenirSequence = IIf(IsNull(rstTemp(0)), 1, rstTemp(0) + 1)
rstTemp.Close

End Function

Function ObtenirSequenceAGT() As Long

'Fonction servant a définir le numéro séquentiel relié à l'événement dans la table agent_tb, selon la date du jour,
'repart a zéro a tous les jours

Dim sSql As String
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb

Set rstTemp = db.OpenRecordset("Select max([dataID]) from agent_tb Where [date] = #" & Format(Now, "yyyy-mm-dd") & "#")
ObtenirSequenceAGT = IIf(IsNull(rstTemp(0)), 1, rstTemp(0) + 1)
rstTemp.Close

End Function

Function ObtenirSequenceAGTsame() As Long

'Fonction servant a définir le numéro séquentiel relié à l'événement dans la table agent_tb, selon la date du jour,
'repart a zéro a tous les jours

Dim sSql As String
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb

Set rstTemp = db.OpenRecordset("Select max([dataID]) from agent_tb Where [date] = #" & Format(Now, "yyyy-mm-dd") & "#")
ObtenirSequenceAGTsame = IIf(IsNull(rstTemp(0)), 1, rstTemp(0))
rstTemp.Close

End Function
Function ObtenirSequenceAGTAdd() As Long

'Fonction servant a définir le numéro séquentiel relié à l'événement dans la table agent_tb, selon la date du jour,
'repart a zéro a tous les jours

Dim sSql As String
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb

Set rstTemp = db.OpenRecordset("Select max([dataID]) from agent_tb Where [date] = #" & Format(Now, "yyyy-mm-dd") & "#")
ObtenirSequenceAGTAdd = IIf(IsNull(rstTemp(0)), 1, rstTemp(0) + 1)
rstTemp.Close

End Function









Can you please explain it to me...
 
What you've experiencing from testing is intended behavior as you're dealing with a multi-user environment...

It's got nothing to do with your code.

If in a production environment you're dealing with more users, you'll have to set up security (workgroups) and / or split up your database in a back end and a front end.

Search this forum as this topic (security / muti-user) has been posted before.
 

Users who are viewing this thread

Back
Top Bottom