I have a save button on my form which opens a recordset and saves the data to the table. If the user clicks on the button twice by mistake it will save the data twice in two separate records. I will actually get two rows in the table with identical information (with different primary key values).
When the user clicks on "Save" the following function is called:
AddToIncidentTable
Function definition:
Sub AddToIncidentTable() 'testing code to add a new record....
Dim cnThisConnect As ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
With rst
.Open "tblIncident", cnThisConnect, adOpenKeyset, adLockOptimistic, adCmdTable
.AddNew
!DateOcc = Me.txtDate.Value
!TimeOcc = Me.txtTime.Value
!ReviewTeam = Me.txtRevTeam.Value
!Incident = Me.txtAbbIncDesc.Value 'assign abbreviated description
!IncidentDescription = Me.txtIncidentDesc 'assign long version of incident description
!CommunicationCompleteasof = Me.txtCommComplete.Value
!PeopleIndividual = Me.cboPI.Value
!PeopleOther = Me.cboPO.Value
!EnvironmentInternaltoBuilding = Me.cboEI.Value
!EnvironmentExternaltoBuilding = Me.cboEE.Value
!PropertyWithinBuilding = Me.cboPW.Value
!PopertyExternaltoBuilding = Me.cboPE.Value
!SocialPsychologicalIndividual = Me.cboSPI.Value
!SocialPsychologicalCommunity = Me.cboSPC.Value
!OpinionIndividual = Me.cboOInd.Value
!OpinionCommunity = Me.cboOC.Value
!HighestLevel = bytHighestLevelAtt
.Update
lngIncID = !IncidentID
End With
'lngIncID = .IncidentID
rst.Close
Set rst = Nothing
Debug.Print lngIncID, "test of autonumber capture"
End Sub
I know some of these table attribute names are silly but I am modifying an existing accident tracking system so I am stuck with them. Any help with this would be greatly appreciated.
Polnichek
When the user clicks on "Save" the following function is called:
AddToIncidentTable
Function definition:
Sub AddToIncidentTable() 'testing code to add a new record....
Dim cnThisConnect As ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
With rst
.Open "tblIncident", cnThisConnect, adOpenKeyset, adLockOptimistic, adCmdTable
.AddNew
!DateOcc = Me.txtDate.Value
!TimeOcc = Me.txtTime.Value
!ReviewTeam = Me.txtRevTeam.Value
!Incident = Me.txtAbbIncDesc.Value 'assign abbreviated description
!IncidentDescription = Me.txtIncidentDesc 'assign long version of incident description
!CommunicationCompleteasof = Me.txtCommComplete.Value
!PeopleIndividual = Me.cboPI.Value
!PeopleOther = Me.cboPO.Value
!EnvironmentInternaltoBuilding = Me.cboEI.Value
!EnvironmentExternaltoBuilding = Me.cboEE.Value
!PropertyWithinBuilding = Me.cboPW.Value
!PopertyExternaltoBuilding = Me.cboPE.Value
!SocialPsychologicalIndividual = Me.cboSPI.Value
!SocialPsychologicalCommunity = Me.cboSPC.Value
!OpinionIndividual = Me.cboOInd.Value
!OpinionCommunity = Me.cboOC.Value
!HighestLevel = bytHighestLevelAtt
.Update
lngIncID = !IncidentID
End With
'lngIncID = .IncidentID
rst.Close
Set rst = Nothing
Debug.Print lngIncID, "test of autonumber capture"
End Sub
I know some of these table attribute names are silly but I am modifying an existing accident tracking system so I am stuck with them. Any help with this would be greatly appreciated.
Polnichek