OzGrid / Et Al,
I think I'm just being dense here.
I have a table that:
Name: tbl_Coat_ResistCost
Field1: ResistCost ( Text, 50 )
Field2: CostPerLiter ( Number, Double, 2 )
I have an INSERT query of: ( it works when ran from Access )
INSERT INTO tbl_Coat_ResistCost ( CostPerLiter, ResistType )
VALUES ([Tgt ResistCost], [Tgt ResistID]);
Now in excel I've got this routine which wants to use the above query to add new values.
Sub UpdateResistCost(strResistID As String, strResistCost As String, Optional blnAddResist As Boolean)
' Local Variables
Dim adoRst As ADODB.Recordset
Dim adoCmd As ADODB.Command
Dim adoPrm As ADODB.Parameter
' Data on this sheet dependent on data queried from database ( create a readonly recordset attached to the database )
Call OpenCloseDatabase(madoConnRW, "OpenRW")
' Get all available "PRG ID's" ( qry_CoatPrg_AllPrgIDs )
Set adoCmd = New ADODB.Command
With adoCmd
.ActiveConnection = madoConnRW
If blnAddResist Then .CommandText = "qry_CoatPrg_AddNewResist"
If Not blnAddResist Then .CommandText = "qry_CoatPrg_UpdateResistCost"
.CommandType = adCmdStoredProc
End With
Set adoPrm = adoCmd.CreateParameter("Tgt ResistID", adVarChar, adParamInput, 50)
adoCmd.Parameters.Append adoPrm
adoCmd.Parameters("Tgt ResistID") = Trim(strResistID)
Set adoPrm = adoCmd.CreateParameter("Tgt ResistCost", adDouble, adParamInput, 2)
adoCmd.Parameters.Append adoPrm
adoCmd.Parameters("Tgt ResistCost") = CDbl(strResistCost)
' Execute database request and return data
Set adoRst = New ADODB.Recordset
[U]Set adoRst = adoCmd.Execute [SIZE="6"]' (ERRORS HERE)[/SIZE][/U]
adoRst.Close
Set adoRst = Nothing
End Sub
Display More
The error that I get is in the attached file.
"Data Type Mismatch"
Now I've been trying to change the "adDouble" because I'm 99% certain it's not the "adVarChar". Yes, the calling routine verifyes the appropriate values of the first two incomming values.
The "blnAddResist" value is "TRUE" at run time.
The routine which creates the connection follows. I've highlighted the section that creates the connection object in this instance.
Sub OpenCloseDatabase(adoConn As Object, strConnect As String)
' Local Variables
Dim strDataBase As String, strConnection As String
' Step 2 : Set connection variables for database object
strDataBase = Worksheets("Application Data").Range("ad_Database_PhotoInfo").Offset(0, 1) & Worksheets("Application Data").Range("ad_Database_PhotoInfo").Offset(0, 2)
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDataBase & ";"
' Step 2 : Open link to database READONLY
If strConnect = "Open" Then
If Not adoConn Is Nothing Then Exit Sub
Set adoConn = New ADODB.Connection
With adoConn
.Open (strConnection)
.CursorLocation = adUseClient
End With
End If
[SIZE="4"][B]' Step 2 : Open link to database READWRITE
If strConnect = "OpenRW" Then
If Not adoConn Is Nothing Then Exit Sub
Set adoConn = New ADODB.Connection
With adoConn
.Open (strConnection)
End With
End If
[/B][/SIZE]
' Step 3 : Close linke to database
If strConnect = "Close" Then
If adoConn Is Nothing Then Exit Sub
With adoConn
.Close
End With
Set adoConn = Nothing
End If
End Sub
Display More