I am working in an adp file with SS2K and am getting this error when running the code below. Basically, I am changing the unique identifiers of all the universities in the database. To do this, I first have to insert a new record with the new UnivID and the associated information from the old UnivID, then, of course, proceed with the pertinent steps that follow, but this is the step I'm hung up on.
I have a form in which I enter both the old UnivID and the new UnivID I want to change it to, then I click the command button with the code below. I'm not having an issue with changing the UnivID itself, but with the associated information I must insert with it. There are four types of universities (Christian, Government, Private, Other), each of which are simply bit fields in the table and passed to the sproc as adTinyInt.
Now to the strange part. The code only gives the error when one of the bit fields is set to True. When the bit fields are set to False, the code runs fine. I don't know what's wrong.
Con and Com are global variables for my connection object and command object, respectively.
Private Sub cmdCreateNewUnivID_Click()
Dim rsOldUniv As New ADODB.Recordset
Dim strOldUnivSQL As String
strOldUnivSQL = "select * from dbo.tblUniversity where UnivID = " & "'" & Me.txtOldUnivID & "'"
'Pull old university info into recordset
Set Com = New ADODB.Command
With Com
.ActiveConnection = Con
.CommandType = adCmdText
.CommandText = strOldUnivSQL
End With
Set rsOldUniv = Com.Execute
'Create new university record with new ID
Set Com = New ADODB.Command
With Com
.ActiveConnection = Con
.CommandType = adCmdStoredProc
.CommandText = "spChangeUnivCodes"
.Parameters.Append .CreateParameter("@UnivIDVal", adVarChar, adParamInput, 8, Trim(txtNewUnivID.Value))
.Parameters.Append .CreateParameter("@CountryIDVal", adVarChar, adParamInput, 2, rsOldUniv("CountryID"))
.Parameters.Append .CreateParameter("@UnivNameVal", adVarChar, adParamInput, 200, rsOldUniv("UnivName"))
.Parameters.Append .CreateParameter("@ChristUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("ChristianUniv"))
.Parameters.Append .CreateParameter("@GovtUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("GovtUniv"))
.Parameters.Append .CreateParameter("@PrivateUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("PrivateUniv"))
.Parameters.Append .CreateParameter("@OtherUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("OtherUniv"))
End With
Com.Execute
End Sub
I have a form in which I enter both the old UnivID and the new UnivID I want to change it to, then I click the command button with the code below. I'm not having an issue with changing the UnivID itself, but with the associated information I must insert with it. There are four types of universities (Christian, Government, Private, Other), each of which are simply bit fields in the table and passed to the sproc as adTinyInt.
Now to the strange part. The code only gives the error when one of the bit fields is set to True. When the bit fields are set to False, the code runs fine. I don't know what's wrong.
Con and Com are global variables for my connection object and command object, respectively.
Private Sub cmdCreateNewUnivID_Click()
Dim rsOldUniv As New ADODB.Recordset
Dim strOldUnivSQL As String
strOldUnivSQL = "select * from dbo.tblUniversity where UnivID = " & "'" & Me.txtOldUnivID & "'"
'Pull old university info into recordset
Set Com = New ADODB.Command
With Com
.ActiveConnection = Con
.CommandType = adCmdText
.CommandText = strOldUnivSQL
End With
Set rsOldUniv = Com.Execute
'Create new university record with new ID
Set Com = New ADODB.Command
With Com
.ActiveConnection = Con
.CommandType = adCmdStoredProc
.CommandText = "spChangeUnivCodes"
.Parameters.Append .CreateParameter("@UnivIDVal", adVarChar, adParamInput, 8, Trim(txtNewUnivID.Value))
.Parameters.Append .CreateParameter("@CountryIDVal", adVarChar, adParamInput, 2, rsOldUniv("CountryID"))
.Parameters.Append .CreateParameter("@UnivNameVal", adVarChar, adParamInput, 200, rsOldUniv("UnivName"))
.Parameters.Append .CreateParameter("@ChristUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("ChristianUniv"))
.Parameters.Append .CreateParameter("@GovtUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("GovtUniv"))
.Parameters.Append .CreateParameter("@PrivateUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("PrivateUniv"))
.Parameters.Append .CreateParameter("@OtherUnivVal", adTinyInt, adParamInput, 1, rsOldUniv("OtherUniv"))
End With
Com.Execute
End Sub