Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2005, 04:20 AM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO UPDATE Errors

This is only my 2nd posting. I'm not sure of the protocol so don't hesitate to set me straight. Anyway I'm using Excel VBA w/Jet ADO to access a text file called stgenlist.csv which has a header row. The 1st column is "Insid" which is a unique identifier. "Ma" is the 10th column and is a float. Please take a look at the following code modified from page 401 of Excel 2002 Programmers..Ref. So far, I'm able to INSERT a new record but when I get to the UPDATE portion I keep getting a

"No Value Given for one or more parameters" error

I've been stepping thru the code to make it work.

Here's the code
=========================================
Public Sub InsertUpdateDelete()

    Dim objCommand As ADODB.Command
    Dim rsData As ADODB.Recordset
    Dim lRecordsAffected As Long
    Dim lKey As Long
    Dim szConnect As String
    Dim FileName As String
    Dim IdType1 As String
    Dim IdType2 As String
    Dim Id As String
    Dim CompID As String


    On Error GoTo ErrorHandler

   CompID = "ST"
   FileName = CompID & "GenList.csv"
   IdType1 = "Insid"
   IdType2 = "Insdate"
   Id = "TestID1"

    Set wbBook = ThisWorkbook
    Set wsSheet = wbBook.Worksheets("LbData")

    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset

    stDB = ThisWorkbook.Path & "\Data\" & CompID & "data\"

    szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=" & stDB & ";" & _
                "Extended Properties=Text;"

    ' Create the Command object we'll use for all three queries.
    Set objCommand = New ADODB.Command
    objCommand.ActiveConnection = szConnect

    '**** INSERT a new record into the database **************
    ' Load the SQL string into the Command object.
    objCommand.CommandText = "INSERT INTO " & FileName & "(" & IdType1 & "," & IdType2 & ",batid) " & _
    "VALUES('" & Id & "','1/1/2001','aa1');"

    ' Execute the SQL statement.
    objCommand.Execute Recordsaffected:=lRecordsAffected, _
                       Options:=adCmdText Or adExecuteNoRecords
    ' Check for errors. Only one record should have been affected.
    If lRecordsAffected <> 1 Then Err.Raise Number:=vbObjectError + 1024, _
          Description:="Error executing INSERT statement."

'################################################# ################
 'HERE'S THE PROBLEM AREA, If it works as anticipated, we should
'find the newly inserted record by it's "insid" and update the "Ma" column
'with the value 1.234

    '**** UPDATE the record we just created ******************
    ' Load the SQL string into the Command object.

    objCommand.CommandText = "UPDATE " & FileName & _
    " SET Ma= '1.234' WHERE Insid= " & Id & " ;"
    ' Execute the SQL statement.
    objCommand.Execute Recordsaffected:=lRecordsAffected, _
                       Options:=adCmdText Or adExecuteNoRecords
    ' Check for errors. Only one record should have been affected.
    If lRecordsAffected <> 1 Then Err.Raise Number:=vbObjectError + 1024, _
          Description:="Error executing UPDATE statement."



ErrorExit:

    ' Destroy our ADO objects.
    Set objCommand = Nothing
    Set rsData = Nothing
    Exit Sub

ErrorHandler:
    MsgBox Err.Description, vbCritical
    Resume ErrorExit
End Sub


Rene





Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO querying Excel errors nautica Excel VBA 0 April 28th, 2006 08:25 AM
Intercepting ADO Errors in VB6 mike123abc Pro VB Databases 1 January 28th, 2005 11:08 PM
ASP Insert/Update code causes errors lewdogg Classic ASP Databases 4 January 25th, 2005 04:24 AM
Intercept ADO Errors mike123abc Pro VB Databases 1 September 28th, 2004 07:33 AM
DataGrid .. XML .. Errors to update sean XML 2 July 10th, 2003 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.