I have created 2 VBA routines that call 2 different SQL Server Stored Procedures which are virtually identical. However one routine was working to update a Column in the RecordSet, the other wasn't working. No idea at all what was wrong.
In order to possibly resolve it and in any case, to maybe improve it, I amended the RecordSet definition so that the Columns were changed from Bit to Char and I am now passing a "Y" or a "N" rather than 0 or 1.
Everything in the Database looks OK (details below), the Columns are declared as Char and it Builds & Deploys just fine. However, the VBA program is now throwing an error
"Run-time Error -2147217913(80040e07) Error converting data type char to bit."
Can anybody please tell me why it is doing this ?
Option Explicit
Option Base 1
Option Compare Text
Sub UpdateEmailsFixtureList()
Set KA_Com = New ADODB.Command
KA_Com.CommandText = "UpdateEmails"
KA_Com.CommandType = adCmdStoredProc
Set KA_Parameter = KA_Com.CreateParameter(Name:="pLeagueId", Type:=adInteger)
KA_Com.Parameters.Append KA_Parameter
KA_Com.Parameters("pLeagueId").Value = KA_RS_Leagues![ID]
Set KA_Parameter = KA_Com.CreateParameter(Name:="pFixtureList", Type:=adChar, Size:=1)
KA_Com.Parameters.Append KA_Parameter
KA_Com.Parameters("pFixtureList").Value = "Y"
Set KA_Com.ActiveConnection = KA_DB
Set KA_RS_Emails = KA_Com.Execute ***<<<<< Error occurs here <<<<<***
End Sub
The new RecordSet Create ...
CREATE TABLE [dbo].[Emails]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY,
[ManagerList] CHAR NOT NULL DEFAULT 'N',
[FixtureList] CHAR NOT NULL DEFAULT 'N',
[Shomatch] CHAR NOT NULL DEFAULT 'N',
[Newsletter] CHAR NOT NULL DEFAULT 'N',
[Turn] CHAR NOT NULL DEFAULT 'N',
[Started] CHAR NOT NULL DEFAULT 'N',
[Sent] CHAR NOT NULL DEFAULT 'N',
[Acknowledged] CHAR NOT NULL DEFAULT 'N',
[League] INT NOT NULL,
CONSTRAINT [FK_Emails_League] FOREIGN KEY ([League]) REFERENCES [Leagues]([Id])
)
The Stored Procedure ...
CREATE PROCEDURE [dbo].[UpdateEmailsFixtureList]
@pLeagueId int,
@pFixtureList char(1)
AS
UPDATE [dbo].[Emails]
SET [FixtureList] = @pFixtureList
WHERE [League] = @pLeagueId;
GO
YandNis unlikely to offer any advantage whatsoever, as far as I can tell all you have done is increase the storage, and increase the allowable number of values. Also, you should always specify a length when using CHAR/NCHAR/VARCHAR/NVARCHAR. It would have been a much better idea to try and resolve whatever issue a BIT column was causing.