dcsimg
Results 1 to 26 of 26

Thread: [RESOLVED] Run Time Error 3201

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Resolved [RESOLVED] Run Time Error 3201

    Code:
    Private Sub cmdSave_Click()
    If UserDelete = vbNullString Then
                MsgBox "Please choose a record in the list to Update.", vbExclamation, "Warning!"
                Exit Sub
            Else
                Set Record = New ADODB.Recordset
                Dim ssql As String
                ssql = "Select * from payment where cusmob ='" & UserDelete & "'"
                    Record.Open ssql, Connect, adOpenDynamic, adLockOptimistic
                With Record
                .Update
                    !paid = Text1.Text
                    !bal = Text3.Text
                    !pdate = Text2.Text
                    !less = Text4.Text
                    .Update
                    Call RefOrders
                    .Close
                End With
                Set Record = Nothing
                MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
                ClearTextBox frmUpdate_Ords
                Exit Sub
            End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,519

    Re: Run Time Error 3201

    It will help if you at least said which line the error occurs on

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Sorry Sir
    Error on this line !paid = Text1.Text

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,499

    Re: Run Time Error 3201

    Well, since 3201 refers to BOF/EOF = True
    have you checked if your query returns something?

    EDIT: At a guess: I think it might be the Update statement in the line before the line which throws you an error
    Code:
    With Record
                .Update
                !paid = Text1.Text
    EDIT2: FWIW
    1) since it's a single table being updated i'd rather use an UPDATE-SQL against it
    2) Use parameters (either the way you're doing it with the SELECT beforehand, or my way with the UPDATE-SQL)
    Last edited by Zvoni; Nov 9th, 2018 at 02:07 AM.
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Nothing Returns Breaks on 3201 Error

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,499

    Re: Run Time Error 3201

    Did you remove the Line i've written in red above?
    Did you do a Debug.Print Record.RecordCount directly after opening the Recordset (and before your With-Block)?
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    @Zvoni i have done as mentioned by you
    But,still same error msg

  8. #8
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,214

    Re: Run Time Error 3201

    What's the result (output) of:
    Debug.Print Record.RecordCount

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    No Output in Debug also

  10. #10
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,214

    Re: Run Time Error 3201

    Show the exact code you are using.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Code:
    Private Sub cmdSave_Click()
    If UserDelete = vbNullString Then
                MsgBox "Please choose a record in the list to Update.", vbExclamation, "Warning!"
                Exit Sub
            Else
                Set Record = New ADODB.Recordset
                Dim ssql As String
                ssql = "Select * from payment where cusmob='" & UserDelete & "'"
                    Record.Open ssql, Connect, adOpenDynamic, adLockOptimistic
                With Record
                    !paid = Text1.Text-------------------> Error In this Line
                    !pdate = Text2.Text
                    !less = Text4.Text
                    !bal = Text3.Text
                    .Update
                    Call RefOrders
                    .Close
                End With
                Set Record = Nothing
                MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
                Exit Sub
            End If
    End Sub

  12. #12

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Code:
    Private Sub cmdSave_Click()
    If UserDelete = vbNullString Then
                MsgBox "Please choose a record in the list to Update.", vbExclamation, "Warning!"
                Exit Sub
            Else
                Set Record = New ADODB.Recordset
                Dim ssql As String
                ssql = "Select * from payment where cusmob='" & UserDelete & "'"
                    Record.Open ssql, Connect, adOpenDynamic, adLockOptimistic
                With Record
                    !paid = Text1.Text-------------------> Error In this Line
                    !pdate = Text2.Text
                    !less = Text4.Text
                    !bal = Text3.Text
                    .Update
                    Call RefOrders
                    .Close
                End With
                Set Record = Nothing
                MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
                Exit Sub
            End If
    End Sub

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,499

    Re: Run Time Error 3201

    Code:
    Private Sub cmdSave_Click()
    If UserDelete = vbNullString Then
                MsgBox "Please choose a record in the list to Update.", vbExclamation, "Warning!"
                Exit Sub
            Else
                Set Record = New ADODB.Recordset
                Dim ssql As String
                ssql = "Select * from payment where cusmob='" & UserDelete & "'"
                    Record.Open ssql, Connect, adOpenDynamic, adLockOptimistic
                Debug.Print Record.RecordCount
                With Record
                    !paid = Text1.Text-------------------> Error In this Line
                    !pdate = Text2.Text
                    !less = Text4.Text
                    !bal = Text3.Text
                    .Update
                    Call RefOrders
                    .Close
                End With
                Set Record = Nothing
                MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
                Exit Sub
            End If
    End Sub
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  14. #14
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,214

    Re: Run Time Error 3201

    So you did NOT include the Debug.Print statement, of course you don't see anything ...
    Code:
    Private Sub cmdSave_Click()
      If UserDelete = vbNullString Then
        MsgBox "Please choose a record in the list to Update.", vbExclamation, "Warning!"
        Exit Sub
      Else
        Set Record = New ADODB.Recordset
        Dim ssql As String
        ssql = "Select * from payment where cusmob='" & UserDelete & "'"
        Record.Open ssql, Connect, adOpenDynamic, adLockOptimistic
    
        ' Add the following line
        Debug.Print "Number of items selected: " & Record.RecordCount
        '
    
        With Record
            !paid = Text1.Text
            !pdate = Text2.Text
            !less = Text4.Text
            !bal = Text3.Text
            .Update
            Call RefOrders
            .Close
        End With
        Set Record = Nothing
        MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
        Exit Sub
      End If
    End Sub

  15. #15
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,519

    Re: Run Time Error 3201

    You need to test to see if you have a record and if not then use addnew before trying to set the field values, assuming of course that you want to add the record if there is no match otherwise you would just abort the process and perhaps tell the user that there is no matching record.

    For example
    Code:
    With Record
            if .eof then .Addnew
            !paid = Text1.Text
    or
    Code:
    With Record
           if .eof then exit sub
            !paid = Text1.Text

  16. #16

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Sir
    I Don't want to add new record, wanna update the some fields in that record

  17. #17

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    Sir
    I Don't want to add new record, wanna update the some fields in that record

  18. #18
    Lively Member
    Join Date
    Jun 2018
    Posts
    91

    Re: Run Time Error 3201

    Hello,

    Do you have reserved words in your payment table as field names? If so change them to any other names before trying Select *

    I suspect your field name less might be a reserved word. Try to change it and see. By the way, what is your Database?

    Instead of your Select * from payment..., just try to use SELECT paid, bal, pdate, lessTest from payment...

    ** Assumed you changed the field name less to lessTest

    OR just try with a field alias as below,

    SELECT paid, bal, pdate, less AS lessTest from payment[/COLOR]...
    Last edited by PGBSoft; Nov 10th, 2018 at 02:41 AM.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    @PGBSoft, Same Error

  20. #20
    Lively Member
    Join Date
    Jun 2018
    Posts
    91

    Re: Run Time Error 3201

    Quote Originally Posted by rasheedraj@gmail.com View Post
    @PGBSoft, Same Error
    Did you change your field name [less] to any other?

    Did you see the update in #18?
    Last edited by PGBSoft; Nov 10th, 2018 at 02:42 AM.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    @PGBSoft, same problem, even i changed filed name as suggested by you.

  22. #22
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,499

    Re: Run Time Error 3201

    For the last time: does your query return a recordset?
    check your RecordCount
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  23. #23

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    As suggested by you i have followed all , but debug report not seen any

  24. #24
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,499

    Re: Run Time Error 3201

    If RecordCount is zero, then your query doesn't return anything, meaning:
    the Value for UserDelete is not found in your table. Period!
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  25. #25
    Lively Member
    Join Date
    Jun 2018
    Posts
    91

    Re: Run Time Error 3201

    Quote Originally Posted by rasheedraj@gmail.com View Post
    @PGBSoft, same problem, even i changed filed name as suggested by you.
    Hello,

    The reason why I told you to change the field names and try, is because, if you have used database reserved words directly for field names, the "Select * ...." might get no records, though you have records for the query.

    If this is not the case, as suggested in other posts, your query does not return any records due to absence of [UserDelete for cusmob] in your payment table.

    However, some ideas for you to think:

    Can you show all the field names of your payment table?

    Is cusmob is your primary key in payment table or Do you use composite key? What is the data type of it?

    What does your UserDelete variable actually contain? Do you get it from a master table like CustomerMaster or Do you get it directly from the payment table?

    By the way, I suspect the given variable name UserDelete, are you actually referring something already deleted?

    Have you applied cascade deleting with your payment table?

    All in all, make sure what you assign for your UserDelete variable must be available in your payment table.
    Last edited by PGBSoft; Nov 10th, 2018 at 06:32 AM.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    102

    Re: Run Time Error 3201

    @Zvoni Thanks alot for switiching my mind button....its clear...Actually UserDelete is pointing some other field., i changed, its working now.....Thanks alot @Zvoni,@PGBSoft,@DataMiser

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width