Results 1 to 3 of 3

Thread: Updating Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    27

    Updating Problem

    Hey all, I've been workin on this all afternoon and I can't get it working for the life of me. I have tried it too many ways to count so I will post the few where I think I am the closest. I am simply trying to update a record (in access database) using my visual basic form. Here is the code and associated errors:
    Connection
    Set Rs = New ADODB.Recordset
    Rs.Open "Update T_Questions_Static Set IM_Number = " & txtIM & " AND Meeting_Number = " & txtMeeting & " AND Questions_Static = " & txtStatic & "", Cn, adOpenDynamic, adLockBatchOptimistic, cmdAddText
    Rs.AddNew
    Rs("Meeting_Number") = txtMeeting.Text
    Rs("IM_Number") = txtIM.Text
    Rs("Questions_Static") = txtStatic.Text
    Rs.Update
    Rs.UpdateBatch
    Rs.MoveNext
    Rs.Close
    Set Rs = Nothing

    Error: No value given for one or more required parameters

    Next Try:
    Dim Cm As ADODB.Command
    Dim Rs As ADODB.Recordset

    Set Cm = New ADODB.Command
    With Cm
    .CommandType = adCmdText
    .ActiveConnection = Cn
    .CommandText = "Select * From T_Questions_Static"
    End With
    'Create record set
    Set Rs = New ADODB.Recordset
    Rs.Open Cm, , adOpenStatic, adLockOptimistic
    'Update values for row 1
    Rs.AddNew
    Rs!Meeting_Number = txtMeeting
    Rs!IM_Number = txtIM
    Rs!Questions_Static = txtStatic

    Call Rs.Update
    Set Rs = Nothing
    Set adoCommand = Nothing
    Exit Sub

    Error: THe changes you requested to the table were not successful becayse they would create duplicate values in the index, primary key, etc....

    'Updates to T_Questions_Static Table
    Connection
    Set Rs = New ADODB.Recordset
    Rs.Open "Select * From T_Questions_Static", Cn, 1, 3, AddcmdText
    With DeMeeting.rsQuestions_Static
    Rs("Meeting_Number") = txtMeeting.Text
    Rs("IM_Number") = txtIM.Text
    Rs("Questions_Static") = txtStatic.Text
    DeMeeting.rsQuestions_Static.Update
    End With
    Set Rs = Nothing

    This method kind of works, but it updates the first record in the record set, not the record that it is suppose to update.

    Any help is welcome, or suggestions to try something else would also be great. I was thinking it might possibly be the settings in my database that are causing the errors, but I am not sure.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Updating Problem

    Originally posted by ABCDEFGHIJKL
    1)
    VB Code:
    1. Set Rs = New ADODB.Recordset
    2.         Rs.Open "[b]Update[/b] T_Questions_Static Set IM_Number = " & txtIM & " AND Meeting_Number = " & txtMeeting & " AND Questions_Static = " & txtStatic & "", Cn, adOpenDynamic, adLockBatchOptimistic, cmdAddText
    3.         Rs.AddNew
    4.         Rs("Meeting_Number") = txtMeeting.Text
    5.         Rs("IM_Number") = txtIM.Text
    6.         Rs("Questions_Static") = txtStatic.Text
    7.         Rs.Update
    8.         Rs.UpdateBatch
    9.         Rs.MoveNext
    10.         Rs.Close
    11.         Set Rs = Nothing

    2)
    VB Code:
    1. Dim Cm As ADODB.Command
    2.     Dim Rs As ADODB.Recordset
    3.  
    4.     Set Cm = New ADODB.Command
    5.     With Cm
    6.         .CommandType = adCmdText
    7.         .ActiveConnection = Cn
    8.         .CommandText = "Select * From T_Questions_Static"
    9.     End With
    10.     'Create record set
    11.     Set Rs = New ADODB.Recordset
    12. [b]    Rs.Open Cm, , adOpenStatic, adLockOptimistic[/b]
    13.     'Update values for row 1
    14.     Rs.AddNew
    15.     Rs!Meeting_Number = txtMeeting
    16.     Rs!IM_Number = txtIM
    17.     Rs!Questions_Static = txtStatic
    18.      
    19.     Call Rs.Update
    20.      Set Rs = Nothing
    21.     Set adoCommand = Nothing
    22.     Exit Sub

    3)
    VB Code:
    1. 'Updates to T_Questions_Static Table
    2.     Connection
    3.         Set Rs = New ADODB.Recordset
    4. [b]        Rs.Open "Select * From T_Questions_Static", Cn, 1, 3, AddcmdText[/b]
    5. [color=red]        With DeMeeting.rsQuestions_Static[/color]
    6.             Rs("Meeting_Number") = txtMeeting.Text
    7.             Rs("IM_Number") = txtIM.Text
    8.             Rs("Questions_Static") = txtStatic.Text
    9.             DeMeeting.rsQuestions_Static.Update
    10. [color=red]        End With[/color]
    11.         Set Rs = Nothing
    1)
    Update??? Don't you mean Select?
    Error suggests that you have specified a value but its not recognising it, so you'd need to debug.print the sql statement before opening it.

    2)
    Bits in bold...
    rs.open strSql,connection, adOpenStatic, adLockOptimistic,adCmdText
    open static - not updateable - its a snapshot - you need dynamic to open and edit/update. static for recordcount/view only.
    use rs("fieldname") .. nicer than rs![fieldname]

    3)
    Rs.Open "Select * From T_Questions_Static", Cn, 2, 3, 1
    Bits in red are not needed
    This should work...
    And will if you put rs.Addnew before trying to add a new record lol


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    27
    Thanks for the help buddy. I got it working, although I had to add a little extra to get it working. Here is the code incase anyone out there in the future is doing something similar to me.

    'Updates to T_Questions_Static Table
    Connection
    Set Rs = New ADODB.Recordset
    Rs.Open "Select * From T_Questions_Static Where IM_Number = " & txtMeeting & " and Meeting_Number = " & txtMeeting & "", Cn, 2, 3, 1
    'Rs("Meeting_Number") = txtMeeting.Text
    'Rs("IM_Number") = txtIM.Text
    Rs("Questions_Static") = txtStatic.Text
    Rs.Update
    Rs.MoveFirst
    Set Rs = Nothing

    Thanks again Ecniv, you the MAANNNNN!!!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width