ScoobyTwo
asked on
Run-time error
Error message when using an application developed in VB6 which connects to a database using ODBC SQL.
Run-Time Error '2147217900 (80040e14)
[Microsoft][ODBC SQL Server Driver][SQL Server] An Explicit value for the identity column in table 'applicationform' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Any ideas on what this means - In English ??
Run-Time Error '2147217900 (80040e14)
[Microsoft][ODBC SQL Server Driver][SQL Server] An Explicit value for the identity column in table 'applicationform' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Any ideas on what this means - In English ??
Are you trying to use @@Identity with Microsoft Access 97. If yes then it wont work with 97 but works with Access 2000 or later.
If you have a table which has an identity field contained within it such as a unique row identifier, you will get this message if you attempt to specify a value for this field in an insert or update statement.
There are basically two ways to resolve the issue;
1) Don't try to set a value for this field yourself, let SQL do it:
Insert Into MyTable (Field1,Field2) Values('MyValue1',100)
Where MyTable has three fields:
KeyField int Identity(1,1)
Field1 varchar(200)
Field2 int
2) If you must specify the value yourself for some reason:
Set IDENTITY_INSERT MyTable ON
Insert Into MyTable (KeyField,Field1,Field2) Values(1234,'MyValue1',100 )
Set IDENTITY_INSERT MyTable OFF
In your SQL batch.
There are basically two ways to resolve the issue;
1) Don't try to set a value for this field yourself, let SQL do it:
Insert Into MyTable (Field1,Field2) Values('MyValue1',100)
Where MyTable has three fields:
KeyField int Identity(1,1)
Field1 varchar(200)
Field2 int
2) If you must specify the value yourself for some reason:
Set IDENTITY_INSERT MyTable ON
Insert Into MyTable (KeyField,Field1,Field2) Values(1234,'MyValue1',100
Set IDENTITY_INSERT MyTable OFF
In your SQL batch.
ASKER
Sorry for being really dense but I don't really have any experience in this area. (Deep end and dropped !)
What I have found out so far is that one user has this problem on a test machine.
(It works fine for me)
They are trying to save an application form which has been generated using forms produced within a VB6 application which links to a DBO on a SQL Server.
The database (applicationform.dbo) has a number of fields.
One of which is called applicationformid which is listed as the identity field in database properties.
I run on Access 97 on an XP machine - No problem
I believe the user is running on Access 97 on an NT machine.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_7zas.asp
Above site says :
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.
I tried opening several instances of the program to see if that might have caused the problem of a SET IDENTITY_INSERT ON but it worked fine. Searched through the VB code to see if I could identify at which point the SET was happening but couldn't see any mention of it. ?
What I have found out so far is that one user has this problem on a test machine.
(It works fine for me)
They are trying to save an application form which has been generated using forms produced within a VB6 application which links to a DBO on a SQL Server.
The database (applicationform.dbo) has a number of fields.
One of which is called applicationformid which is listed as the identity field in database properties.
I run on Access 97 on an XP machine - No problem
I believe the user is running on Access 97 on an NT machine.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_7zas.asp
Above site says :
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.
I tried opening several instances of the program to see if that might have caused the problem of a SET IDENTITY_INSERT ON but it worked fine. Searched through the VB code to see if I could identify at which point the SET was happening but couldn't see any mention of it. ?
Ok, do you have the code for the area around where the problem occurs?
ASKER
Sorry for being really dense but I don't really have any experience in this area. (Deep end and dropped !)
What I have found out so far is that one user has this problem on a test machine.
(It works fine for me)
They are trying to save an application form which has been generated using forms produced within a VB6 application which links to a DBO on a SQL Server.
The database (applicationform.dbo) has a number of fields.
One of which is called applicationformid which is listed as the identity field in database properties.
I run on Access 97 on an XP machine - No problem
I believe the user is running on Access 97 on an NT machine.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_7zas.asp
Above site says :
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.
I tried opening several instances of the program to see if that might have caused the problem of a SET IDENTITY_INSERT ON but it worked fine. Searched through the VB code to see if I could identify at which point the SET was happening but couldn't see any mention of it. ?
What I have found out so far is that one user has this problem on a test machine.
(It works fine for me)
They are trying to save an application form which has been generated using forms produced within a VB6 application which links to a DBO on a SQL Server.
The database (applicationform.dbo) has a number of fields.
One of which is called applicationformid which is listed as the identity field in database properties.
I run on Access 97 on an XP machine - No problem
I believe the user is running on Access 97 on an NT machine.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_7zas.asp
Above site says :
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.
I tried opening several instances of the program to see if that might have caused the problem of a SET IDENTITY_INSERT ON but it worked fine. Searched through the VB code to see if I could identify at which point the SET was happening but couldn't see any mention of it. ?
ASKER
Tim - I believe this is the code that is running. The msg appears when the user tries to save the record.
Private Sub cmdSaveApplicationform_Cli ck()
Dim blnNewCandidate As Boolean
Dim blnDBUpdateOK As Boolean
Dim blnNonUKCitizen As Boolean
Dim blnLegalResident As Boolean
Dim blnImmigrationControl As Boolean
Dim blnUKResidentRestriction As Boolean
Dim blnEnglishWelshFluent As Boolean
Dim blnAbortSave As Boolean
Dim blnValidated As Boolean
Dim blnGuaranteedInterview As Boolean
Dim dtmDateOfBirth As Date
Dim dtmReceivedDate As Date
Dim dtmAdvertDate As Date
Dim intButton As Integer
Dim intTab As Integer
Dim intThisTab As Integer
Dim intCount As Integer
Dim intIndex As Integer
Dim intSalutation As Integer
Dim intCandidateid As Integer
Dim intNationalityAtBirth As Integer
Dim intNationalityNow As Integer
Dim intWelshAbility As Integer
Dim intPreferredInterviewLangu age As Integer
Dim intSource As Integer
Dim strCandidateRef As String
Dim strNextReference As String
Dim strKeyReference As String
Dim strReference As String
Dim strSalutation As String
Dim strFirstName As String
Dim strMiddleName As String
Dim strSurname As String
Dim strNINumber As String
Dim strErrMess As String
Dim strHomePhone As String
Dim strBusinessPhone As String
Dim strMobilePhone As String
Dim strEmail As String
Dim strNonUKCitizenComment As String
Dim strImmigrationControlComme nt As String
Dim strUKResidenceRestrictionC omment As String
Dim strEmploymentGapComment As String
Dim strInterviewRequirement As String
Dim strSourceName As String
Dim strOtherComments As String
Dim strMessage As String
blnAbortSave = False
blnValidated = False
intThisTab = tabApplicationForm.Tab
validateTab intThisTab, False, strErrMess
intTab = 0
While (Not blnValidated) And (Not blnAbortSave)
If strErrMess <> "" Then
intButton = MsgBox(strErrMess, _
vbExclamation, _
"Application Form")
mblnValidationCausedSwitch = True
tabApplicationForm.Tab = intTab
mblnValidationCausedSwitch = False
blnAbortSave = True
Else
validateTab intTab, False, strErrMess
If strErrMess = "" Then
If intTab = 9 Then
blnValidated = True
End If
intTab = intTab + 1
End If
End If
Wend
If blnValidated Then
blnNewCandidate = False
If txtCandidateReference.Text = "" Then
mclsCandidate.fetchNextCan didateRefe rence strNextReference, _
intCount
blnNewCandidate = True
Else
strReference = txtCandidateReference.Text
End If
blnDBUpdateOK = True
'
' Retrieve Candidate information from form
'
intIndex = cboSalutation.ListIndex
mclsSalutation.returnIDfro mComboInde x intIndex, intSalutation
strFirstName = txtFirstName.Text
strMiddleName = txtMiddleName.Text
strSurname = txtSurname.Text
strNINumber = txtNINumber.Text
If txtDateOfBirth.Text <> "" Then
dtmDateOfBirth = txtDateOfBirth.Text
End If
'
' Retrieve ApplicationForm information from form
'
strHomePhone = txtHomePhone.Text
strBusinessPhone = txtBusinessPhone.Text
strMobilePhone = txtMobilePhone.Text
strEmail = txtEmail.Text
intNationalityAtBirth = _
mclsNationalityAtBirth.ret urnIDfromC omboText(c boNational ityAtBirth )
intNationalityNow = _
mclsNationalityNow.returnI DfromCombo Text(cboNa tionalityN ow)
blnNonUKCitizen = checkBoxBoolean(chkNonUKCi tizen)
strNonUKCitizenComment = txtNonUKCitizen.Text
blnLegalResident = checkBoxBoolean(chkLegalRe sident)
blnImmigrationControl = checkBoxBoolean(chkImmigra tionContro l)
strImmigrationControlComme nt = txtImmigrationControl.Text
blnUKResidentRestriction = checkBoxBoolean(chkUKResid enceRestri ction)
strUKResidenceRestrictionC omment = txtUKResidenceRestriction
strEmploymentGapComment = txtEmploymentGapComments.T ext
blnEnglishWelshFluent = checkBoxBoolean(chkEnglish WelshFluen t)
intWelshAbility = mclsWelshAbility.returnIDf romComboTe xt(cboWels hAbility)
If cboInterviewLanguage.Text = "" Then
cboInterviewLanguage.Text = "English"
End If
intPreferredInterviewLangu age = _
mclsInterviewLanguage.retu rnIDfromCo mboText(cb oInterview Language)
blnGuaranteedInterview = checkBoxBoolean(chkGuarant eedIntervi ew)
strInterviewRequirement = txtInterviewRequirements.T ext
dtmReceivedDate = txtReceivedDate.Text
intSource = mclsSource.returnIDfromCom boText(cbo Source)
strSourceName = cboSourceName.Text
If txtAdvertDate.Text <> "" Then
dtmAdvertDate = txtAdvertDate.Text
End If
strOtherComments = txtOtherInf.Text
'
' If its a new candidate Insert Candidate and Application form
' Otherwise Update both.
'
' MsgBox "Salutation " & intSalutation & _
' "Nationality at Birth " & intNationalityAtBirth & _
' "Nationality Now " & intNationalityNow
gclsDBControl.beginTransac tion
If blnNewCandidate Then
intCandidateid = mclsCandidate.insertCandid ate(strNex tReference , _
intSalutation, _
strFirstName, _
strMiddleName, _
strSurname, _
strNINumber, _
dtmDateOfBirth, _
intCount)
gintApplicationFormID = mclsApplicationForm.insert Applicatio nForm( _
intCandidateid, strHomePhone, _
strBusinessPhone, _
strMobilePhone, _
strEmail, _
intNationalityAtBirth, _
intNationalityNow, _
blnNonUKCitizen, _
strNonUKCitizenComment, _
blnLegalResident, _
blnImmigrationControl, _
strImmigrationControlComme nt, _
blnUKResidentRestriction, _
strUKResidenceRestrictionC omment, _
strEmploymentGapComment, _
blnEnglishWelshFluent, _
intWelshAbility, _
intPreferredInterviewLangu age, _
blnGuaranteedInterview, _
strInterviewRequirement, _
dtmReceivedDate, _
intSource, _
strSourceName, _
dtmAdvertDate, strOtherComments, _
intCount)
Else
strKeyReference = txtCandidateReference.Text
intCandidateid = mclsCandidate.updateCandid ate(strKey Reference, _
intSalutation, _
strFirstName, _
strMiddleName, _
strSurname, _
strNINumber, _
dtmDateOfBirth, _
intCount)
mclsApplicationForm.update Applicatio nForm gintApplicationFormID, intCandidateid, _
strHomePhone, _
strBusinessPhone, _
strMobilePhone, _
strEmail, _
intNationalityAtBirth, _
intNationalityNow, _
blnNonUKCitizen, _
strNonUKCitizenComment, _
blnLegalResident, _
blnImmigrationControl, _
strImmigrationControlComme nt, _
blnUKResidentRestriction, _
strUKResidenceRestrictionC omment, _
strEmploymentGapComment, _
blnEnglishWelshFluent, _
intWelshAbility, _
intPreferredInterviewLangu age, _
blnGuaranteedInterview, _
strInterviewRequirement, _
dtmReceivedDate, _
intSource, _
strSourceName, _
dtmAdvertDate, strOtherComments, _
intCount
End If
If blnDBUpdateOK Then
blnDBUpdateOK = False
If mclsAddress.updateDBfromFl ex(msgAddr ess) Then
If mclsLanguageAbility.update DBfromFlex (msgLangua ges) Then
If mclsPreviousEmployment.upd ateDBfromF lex(msgPre viousEmplo yment) Then
If mclsProfQualifications.upd ateDBfromF lex(msgPro fQuals) Then
If mclsQualifications.updateD BfromFlex( msgEduQual s) Then
If mclsReferee.updateDBfromFl ex(msgRefe rees) Then
If mclsRelation.updateDBfromF lex(msgRel ations) Then
If mclsVacancyApplication.upd ateDBfromF lex _
(msgVacancies) Then
blnDBUpdateOK = True
End If
End If
End If
End If
End If
End If
End If
End If
End If
If blnDBUpdateOK Then
gclsDBControl.commitTransa ction
If blnNewCandidate Then
strMessage = "Candidate has been added to the database." + _
vbCrLf + vbCrLf + _
"Assigned Candidate Reference Number: " + _
strNextReference + vbCrLf + vbCrLf + _
"Do you want to enter/modify Equal Opportunity data now"
Else
strMessage = "Candidate/Application form updated succesfully" + _
vbCrLf + vbCrLf + _
"Do you want to enter/modify Equal Opportunity data now"
End If
intButton = MsgBox(strMessage, _
vbYesNo, "Application Form")
If intButton = vbYes Then
openForm frmEqualOpportunities, False
End If
' clearApplicationForm
Else
gclsDBControl.rollbackTran saction
MsgBox "Database error prevented changes from being applied", _
vbExclamation + vbOKOnly, "ApplicationForm"
End If
End If
End Sub
Private Sub cmdSaveApplicationform_Cli
Dim blnNewCandidate As Boolean
Dim blnDBUpdateOK As Boolean
Dim blnNonUKCitizen As Boolean
Dim blnLegalResident As Boolean
Dim blnImmigrationControl As Boolean
Dim blnUKResidentRestriction As Boolean
Dim blnEnglishWelshFluent As Boolean
Dim blnAbortSave As Boolean
Dim blnValidated As Boolean
Dim blnGuaranteedInterview As Boolean
Dim dtmDateOfBirth As Date
Dim dtmReceivedDate As Date
Dim dtmAdvertDate As Date
Dim intButton As Integer
Dim intTab As Integer
Dim intThisTab As Integer
Dim intCount As Integer
Dim intIndex As Integer
Dim intSalutation As Integer
Dim intCandidateid As Integer
Dim intNationalityAtBirth As Integer
Dim intNationalityNow As Integer
Dim intWelshAbility As Integer
Dim intPreferredInterviewLangu
Dim intSource As Integer
Dim strCandidateRef As String
Dim strNextReference As String
Dim strKeyReference As String
Dim strReference As String
Dim strSalutation As String
Dim strFirstName As String
Dim strMiddleName As String
Dim strSurname As String
Dim strNINumber As String
Dim strErrMess As String
Dim strHomePhone As String
Dim strBusinessPhone As String
Dim strMobilePhone As String
Dim strEmail As String
Dim strNonUKCitizenComment As String
Dim strImmigrationControlComme
Dim strUKResidenceRestrictionC
Dim strEmploymentGapComment As String
Dim strInterviewRequirement As String
Dim strSourceName As String
Dim strOtherComments As String
Dim strMessage As String
blnAbortSave = False
blnValidated = False
intThisTab = tabApplicationForm.Tab
validateTab intThisTab, False, strErrMess
intTab = 0
While (Not blnValidated) And (Not blnAbortSave)
If strErrMess <> "" Then
intButton = MsgBox(strErrMess, _
vbExclamation, _
"Application Form")
mblnValidationCausedSwitch
tabApplicationForm.Tab = intTab
mblnValidationCausedSwitch
blnAbortSave = True
Else
validateTab intTab, False, strErrMess
If strErrMess = "" Then
If intTab = 9 Then
blnValidated = True
End If
intTab = intTab + 1
End If
End If
Wend
If blnValidated Then
blnNewCandidate = False
If txtCandidateReference.Text
mclsCandidate.fetchNextCan
intCount
blnNewCandidate = True
Else
strReference = txtCandidateReference.Text
End If
blnDBUpdateOK = True
'
' Retrieve Candidate information from form
'
intIndex = cboSalutation.ListIndex
mclsSalutation.returnIDfro
strFirstName = txtFirstName.Text
strMiddleName = txtMiddleName.Text
strSurname = txtSurname.Text
strNINumber = txtNINumber.Text
If txtDateOfBirth.Text <> "" Then
dtmDateOfBirth = txtDateOfBirth.Text
End If
'
' Retrieve ApplicationForm information from form
'
strHomePhone = txtHomePhone.Text
strBusinessPhone = txtBusinessPhone.Text
strMobilePhone = txtMobilePhone.Text
strEmail = txtEmail.Text
intNationalityAtBirth = _
mclsNationalityAtBirth.ret
intNationalityNow = _
mclsNationalityNow.returnI
blnNonUKCitizen = checkBoxBoolean(chkNonUKCi
strNonUKCitizenComment = txtNonUKCitizen.Text
blnLegalResident = checkBoxBoolean(chkLegalRe
blnImmigrationControl = checkBoxBoolean(chkImmigra
strImmigrationControlComme
blnUKResidentRestriction = checkBoxBoolean(chkUKResid
strUKResidenceRestrictionC
strEmploymentGapComment = txtEmploymentGapComments.T
blnEnglishWelshFluent = checkBoxBoolean(chkEnglish
intWelshAbility = mclsWelshAbility.returnIDf
If cboInterviewLanguage.Text = "" Then
cboInterviewLanguage.Text = "English"
End If
intPreferredInterviewLangu
mclsInterviewLanguage.retu
blnGuaranteedInterview = checkBoxBoolean(chkGuarant
strInterviewRequirement = txtInterviewRequirements.T
dtmReceivedDate = txtReceivedDate.Text
intSource = mclsSource.returnIDfromCom
strSourceName = cboSourceName.Text
If txtAdvertDate.Text <> "" Then
dtmAdvertDate = txtAdvertDate.Text
End If
strOtherComments = txtOtherInf.Text
'
' If its a new candidate Insert Candidate and Application form
' Otherwise Update both.
'
' MsgBox "Salutation " & intSalutation & _
' "Nationality at Birth " & intNationalityAtBirth & _
' "Nationality Now " & intNationalityNow
gclsDBControl.beginTransac
If blnNewCandidate Then
intCandidateid = mclsCandidate.insertCandid
intSalutation, _
strFirstName, _
strMiddleName, _
strSurname, _
strNINumber, _
dtmDateOfBirth, _
intCount)
gintApplicationFormID = mclsApplicationForm.insert
intCandidateid, strHomePhone, _
strBusinessPhone, _
strMobilePhone, _
strEmail, _
intNationalityAtBirth, _
intNationalityNow, _
blnNonUKCitizen, _
strNonUKCitizenComment, _
blnLegalResident, _
blnImmigrationControl, _
strImmigrationControlComme
blnUKResidentRestriction, _
strUKResidenceRestrictionC
strEmploymentGapComment, _
blnEnglishWelshFluent, _
intWelshAbility, _
intPreferredInterviewLangu
blnGuaranteedInterview, _
strInterviewRequirement, _
dtmReceivedDate, _
intSource, _
strSourceName, _
dtmAdvertDate, strOtherComments, _
intCount)
Else
strKeyReference = txtCandidateReference.Text
intCandidateid = mclsCandidate.updateCandid
intSalutation, _
strFirstName, _
strMiddleName, _
strSurname, _
strNINumber, _
dtmDateOfBirth, _
intCount)
mclsApplicationForm.update
strHomePhone, _
strBusinessPhone, _
strMobilePhone, _
strEmail, _
intNationalityAtBirth, _
intNationalityNow, _
blnNonUKCitizen, _
strNonUKCitizenComment, _
blnLegalResident, _
blnImmigrationControl, _
strImmigrationControlComme
blnUKResidentRestriction, _
strUKResidenceRestrictionC
strEmploymentGapComment, _
blnEnglishWelshFluent, _
intWelshAbility, _
intPreferredInterviewLangu
blnGuaranteedInterview, _
strInterviewRequirement, _
dtmReceivedDate, _
intSource, _
strSourceName, _
dtmAdvertDate, strOtherComments, _
intCount
End If
If blnDBUpdateOK Then
blnDBUpdateOK = False
If mclsAddress.updateDBfromFl
If mclsLanguageAbility.update
If mclsPreviousEmployment.upd
If mclsProfQualifications.upd
If mclsQualifications.updateD
If mclsReferee.updateDBfromFl
If mclsRelation.updateDBfromF
If mclsVacancyApplication.upd
(msgVacancies) Then
blnDBUpdateOK = True
End If
End If
End If
End If
End If
End If
End If
End If
End If
If blnDBUpdateOK Then
gclsDBControl.commitTransa
If blnNewCandidate Then
strMessage = "Candidate has been added to the database." + _
vbCrLf + vbCrLf + _
"Assigned Candidate Reference Number: " + _
strNextReference + vbCrLf + vbCrLf + _
"Do you want to enter/modify Equal Opportunity data now"
Else
strMessage = "Candidate/Application form updated succesfully" + _
vbCrLf + vbCrLf + _
"Do you want to enter/modify Equal Opportunity data now"
End If
intButton = MsgBox(strMessage, _
vbYesNo, "Application Form")
If intButton = vbYes Then
openForm frmEqualOpportunities, False
End If
' clearApplicationForm
Else
gclsDBControl.rollbackTran
MsgBox "Database error prevented changes from being applied", _
vbExclamation + vbOKOnly, "ApplicationForm"
End If
End If
End Sub
ScoobyTwo:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
ScoobyTwo, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:
Refund points and save as a 0-pt PAQ.
DanRollins -- EE database cleanup volunteer
Moderator, my recommended disposition is:
Refund points and save as a 0-pt PAQ.
DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.