dcsimg
Results 1 to 12 of 12

Thread: [RESOLVED] run time error 3201

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Dhaka, Bangladesh
    Posts
    222

    Resolved [RESOLVED] run time error 3201

    for save data and update data I write code this
    Code:
    With rs1
    sSQL = "Select * From duereport Where partyname ='" & cmbPartyName.Text & "'"
    rs1.Open sSQL, con, adOpenDynamic, adLockOptimistic
    If rs1.EOF = False Then
    rs1.Fields("due") = rs1.Fields("due") + Val(Me.txtdue)
    rs1.Update
    End If
    
    If rs1.EOF = True Then
    rs1.Fields("partyname") = cmbPartyName.Text
    rs1.Fields("due") = cmbPartyName.Text
    End If
       End With
    no problem for update data. but when I enter new record then show this massage:
    run time error 3201:
    Either BoF of EOF is true, or the current record has been deleted. requested operation requires a current record.

    and selected this line
    Code:
    rs1.Fields("partyname") = cmbPartyName.Text

  2. #2
    Member
    Join Date
    Feb 2014
    Location
    In my own world
    Posts
    50

    Re: run time error 3201

    Why not try this?
    Code:
    With rs1
    sSQL = "Select * From duereport Where partyname ='" & cmbPartyName.Text & "'"
    rs1.Open sSQL, con, adOpenDynamic, adLockOptimistic
    While rs1.EOF = False
    rs1.Fields("due").value = rs1.Fields("due").value + Val(Me.txtdue)
    rs1.Update
    End While
    
    If rs1.EOF = True Then
    rs1.Fields("partyname").value = cmbPartyName.Text
    rs1.Fields("due").value = cmbPartyName.Text
    rs1.Save
    End if
       End With
    If I am of some help (If that ever happens ) then rate me please . If not then the following sentence should save me: I'm a newbie

  3. #3
    Member
    Join Date
    Feb 2014
    Location
    In my own world
    Posts
    50

    Re: run time error 3201

    Tell me if it works, I haven't testes it but still..
    in the 3rd last line, you could also make it as rsl.addnew, as the record will have to be added anyway..
    If I am of some help (If that ever happens ) then rate me please . If not then the following sentence should save me: I'm a newbie

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,280

    Re: run time error 3201

    Quote Originally Posted by Arsalan View Post
    Why not try this?
    That is an improvement (as specifying which property of an object you want to work with often eliminates bugs), and it would be a good idea to do that... but it wont actually solve the current issue.

    Quote Originally Posted by Arsalan View Post
    you could also make it as rsl.addnew, as the record will have to be added anyway..
    That should solve the current issue

  5. #5
    Member
    Join Date
    Feb 2014
    Location
    In my own world
    Posts
    50

    Re: run time error 3201

    That means I'm improving I tried to fix bugs (if any) and then sort the prob. Hats off to me lol
    If I am of some help (If that ever happens ) then rate me please . If not then the following sentence should save me: I'm a newbie

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Dhaka, Bangladesh
    Posts
    222

    Re: run time error 3201

    It's show compile error and select the line End While

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,280

    Re: run time error 3201

    Whenever you want help with an error, you should always tell us what the error is - because the error message tells us what the problem is.

    In this case I can work it out, but it took a bit of extra time. Rather than this:
    Code:
    While rs1.EOF = False
    ...
    End While
    
    If rs1.EOF = True Then
    ...
    rs1.Save
    End if
    it should have been:
    Code:
    Do While rs1.EOF = False
    ...
    Loop
    
    If rs1.EOF = True And rs1.BOF = True Then
    rs1.AddNew
    ...
    rs1.Update
    End if
    However, it is debatable whether it should be a loop, or left as you had it before... it depends on what you want to happen when/if there are multiple records in the table with the same value for partyname. Using a loop means that they all get updated, which is probably a good idea.

    Quote Originally Posted by Arsalan View Post
    That means I'm improving I tried to fix bugs (if any) and then sort the prob. Hats off to me lol
    That's a good way to do it, and is similar to what I've done to improve myself

  8. #8
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: run time error 3201

    another point i have noticed .the End while is not available in vb6 . so you cannot do the following .
    Code:
    With rs1
    sSQL = "Select * From duereport Where partyname ='" & cmbPartyName.Text & "'"
    rs1.Open sSQL, con, adOpenDynamic, adLockOptimistic
    While rs1.EOF = False
    rs1.Fields("due").value = rs1.Fields("due").value + Val(Me.txtdue)
    rs1.Update
    End While  i don't think it will work
    You can do the following .
    Code:
    With rs1
    sSQL = "Select * From duereport Where partyname ='" & cmbPartyName.Text & "'"
    rs1.Open sSQL, con, adOpenDynamic, adLockOptimistic
    While rs1.EOF = False
    rs1.Fields("due").value = rs1.Fields("due").value + Val(Me.txtdue)
    rs1.Update
    Wend

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Dhaka, Bangladesh
    Posts
    222

    Re: run time error 3201

    the error is:
    compile error:
    expected: if of select of sub or function of property or type or with or enum or end of statement

    if I use do while and loop then it create new data but when I want to update data then it was hung.

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,280

    Re: run time error 3201

    Ah yes, there is actually one more line you need to add:
    Code:
      rs1.Update
      rs1.MoveNext
    Loop

  11. #11
    Member
    Join Date
    Feb 2014
    Location
    In my own world
    Posts
    50

    Re: run time error 3201

    Which line is being highlighted with this error? and which code are you using? mine? quote it please
    If I am of some help (If that ever happens ) then rate me please . If not then the following sentence should save me: I'm a newbie

  12. #12
    Member
    Join Date
    Feb 2014
    Location
    In my own world
    Posts
    50

    Re: run time error 3201

    si is right. After updating, you need to move to the next record
    If I am of some help (If that ever happens ) then rate me please . If not then the following sentence should save me: I'm a newbie

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