Results 1 to 27 of 27

Thread: [RESOLVED]BOF and EOF [/RESOLVED]

  1. #1

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243

    [RESOLVED]BOF and EOF [/RESOLVED]

    Well...
    it's all mendhak's fault

    I changed over my ADO object to the code...

    I having a problem with EOF and BOF. When I reach BOF or EOF I get this error:
    Run-time error '3021':
    Either BOF or EOF is True, or the current record has been deleted.
    Requested operation requires a current record.

    Here is my code:
    VB Code:
    1. Public Sub Form_Load()
    2.  
    3.     Set cn = New ADODB.Connection
    4.     cn.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & App.Path & "\bb-calc.mdb"
    5.     cn.Open
    6.     Set rs = New ADODB.Recordset
    7.     rs.Open "SELECT * from tblBrushBed", cn, adOpenDynamic, adLockPessimistic
    8.     FillFields
    9. End Sub
    10.  
    11. Private Sub cmdPrev_Click()
    12.     If rs.BOF = False Then
    13.         rs.MovePrevious
    14.         FillFields
    15.     End If    
    16. End Sub
    17.  
    18. Private Sub cmdNext_Click()
    19.     If rs.EOF = False Then
    20.         rs.MoveNext
    21.         FillFields
    22.     End If
    23. End Sub
    Last edited by Beengie; Dec 2nd, 2003 at 03:27 AM.
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170


    Is the table in the database empty, by any chance?

  3. #3

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    No, it is not empty.
    I have 3 records in the database.
    It only happens when I try to pass the existing records
    Do I need to do a recordcount, or open the table a different way to make it work?
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: BOF and EOF

    Hmm... Which line gets highlighted?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: BOF and EOF

    Try this:

    VB Code:
    1. Public Sub Form_Load()
    2.  
    3.     Set cn = New ADODB.Connection
    4.     cn.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & App.Path & "\bb-calc.mdb"
    5.     cn.Open
    6.     Set rs = New ADODB.Recordset
    7.     rs.Open "SELECT * from tblBrushBed", cn, adOpenDynamic, adLockPessimistic
    8.     FillFields
    9. End Sub
    10.  
    11. Private Sub cmdPrev_Click()
    12. rs.MovePrevious
    13.  
    14.     If rs.BOF Then
    15.         rs.MoveFirst
    16.     End If    
    17. fillfields
    18. End Sub
    19.  
    20. Private Sub cmdNext_Click()
    21. rs.MoveNext
    22.     If rs.EOF  Then
    23.         rs.MoveLast
    24.     End If
    25. FillFields
    26. End Sub

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    Beengie


    What does FillFields do? Post Code?

  7. #7

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    It highlights the first line below in the fill fields sub
    VB Code:
    1. Public Sub FillFields()
    2.     txtCstmr.Text = rs.Fields("dbCstmr")
    3.     txtDate.Text = rs.Fields("dbDt")
    4.     txtDueDate.Text = rs.Fields("dbDDt")
    5.     txtNPns.Text = rs.Fields("dbNPns")
    6.     txtBrshWdth.Text = rs.Fields("dbBrshWdth")
    7.     txtElev.Text = rs.Fields("dbElvtn")
    8.     txtNDrvs.Text = rs.Fields("dbNDrvs")
    9.     txtFrmSlctn.Text = rs.Fields("dbFrm")
    10.     txtBrngSlctn.Text = rs.Fields("dbBrngs")
    11.     txtChnSlctn.Text = rs.Fields("dbChn")
    12.     txtSprcktSlctn.Text = rs.Fields("dbSprckts")
    13.     txtClntChnSlctn.Text = rs.Fields("dbClntChn")
    14.     txtMDSlctn.Text = rs.Fields("dbMnDrvHP")
    15.     txtGrmtrSlctn.Text = rs.Fields("dbGrMtrBrnd")
    16.     txtHrdwrSlctn.Text = rs.Fields("dbHrdwr")
    17. End Sub

    I tried the example above, got the same errors...
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Can you post the form with the MDB file?

    Your code seems fine.

    (Yeah yeah, all my fault)

  9. #9

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    maybe you can help with other stuff in there also...
    like structure

    * edited *
    Last edited by Beengie; Dec 2nd, 2003 at 03:28 AM.
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Dude... you didn't try the code I gave you!

    VB Code:
    1. Private Sub cmdPrev_Click()
    2. rs.MovePrevious
    3.  
    4.     If rs.BOF Then
    5.         rs.MoveFirst
    6.     End If
    7.     FillFields
    8. End Sub
    9.  
    10.  
    11. Private Sub cmdNext_Click()
    12. rs.MoveNext
    13.  
    14.     If rs.EOF Then
    15.         rs.MoveLast
    16.     End If
    17.     FillFields
    18. End Sub
    19.  
    20. 'Oh, and you forgot...
    21.  
    22. Private Sub cmdClose_Click()
    23. Unload Me
    24.  
    25. End Sub

    It worked fine after i made the above modifications

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    *edit*

  12. #12

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    Originally quoted by Beengie
    I tried the example above, got the same errors...
    I thought that I put that in...
    I don't know what I did wrong, I tried it again and it worked.
    Thanks

    do you have any suggestions for my code?

    this is the first application that I have made with this many calcualtions and variables. Can I be more efficient? Should I do things different?
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Beengie
    Can I be more efficient? Should I do things different?
    Yeah, lot of variables in there. What I'll suggest will be mostly my opinion, so you don't really have to follow it:


    VB Code:
    1. Select Case txtFrmSlctn.Text
    2.         Case "Stainless Steel": T3_4x7_16PFt = 3.2: T3_4X7_16Mtl = txtFrmSlctn.Text ' same as above
    3.         Case "Epoxy": T3_4x7_16PFt = 3.2: T3_4X7_16Mtl = "HR Steel" ' same as above
    4.     End Select

    Could be

    VB Code:
    1. Select Case txtFrmSlctn.Text
    2.  
    3.         Case "Stainless Steel"
    4.          T3_4x7_16PFt = 3.2
    5.          T3_4X7_16Mtl = txtFrmSlctn.Text ' same as above
    6.  
    7.        Case "Epoxy"
    8.        T3_4x7_16PFt = 3.2
    9.         T3_4X7_16Mtl = "HR Steel" ' same as above
    10.  
    11.     End Select

    This is obviously the same thing, but would be for readability, so you know in case some miscalcuations are occuring or erroneous values are being assigned.

    However, looking at the entire form, doing that would require a LOT of changes in there...



    One more thing:

    VB Code:
    1. Select Case nValue
    2.         Case "CrossHQty"
    3.             sngTmpQty = intNSup / 2
    4.             CrossH = sngTmpQty
    5.         Case "CrossHLen"
    6.             sngTmpLngth = (sngFtGdWd * 2) + txtBrshWdth.Text
    7.             CrossH = sngTmpLngth & """"
    8.         Case "CrossHSize"
    9.             CrossH = SQT3x3_16Sz
    10.         Case "CrossHMat"
    11.             CrossH = SQT3x3_16Mtl
    12.         Case "CrossHPFt"
    13.             CrossH = FormatCurrency(SQT3x3_16PFt, 2, 0, 0, -1)
    14.         Case "CrossHMTtl"
    15.             curMkpSnd = sngTmpQty * sngTmpLngth * (SQT3x3_16PFt / 12)
    16.             CrossH = FormatCurrency(curMkpSnd, 2, 0, 0, -1)
    17.             Call fncAdd(curMkpSnd)
    18.         Case "CrossHMkp"
    19.             Call fncMkpMtl(curMkpSnd)
    20.             CrossH = FormatCurrency(curMkpSndT, 2, 0, 0, -1)
    21.     End Select

    You could have a Case Else in there, for incorrect values, so that you know some incorrect value has been assigned, and you can deal with it in some way.

  14. #14

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    I need to finish the data connection buttons (update, add, delete). I haven't converted that yet (sick all weekend). I am planning on taking those hard coded variables out and putting them into a few separate tables for later upating.

    It got carried away when I started copy/pasting and changing variable names. Now you see the reason I wanted to understand my data connection. After further reveiw, I find the dataconnection strings are identical to my uses in ASP. Thank God
    Got any suggestions for add, update, and delete?
    Originally quoted by mendhak
    *edit*
    Is that edit or ribut?
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    For Update, you can simply reverse this:

    VB Code:
    1. txtCstmr.Text = rs.Fields("dbCstmr")
    2.     txtDate.Text = rs.Fields("dbDt")
    3.     txtDueDate.Text = rs.Fields("dbDDt")
    4.     txtNPns.Text = rs.Fields("dbNPns")
    5.     txtBrshWdth.Text = rs.Fields("dbBrshWdth")
    6.     txtElev.Text = rs.Fields("dbElvtn")
    7.     txtNDrvs.Text = rs.Fields("dbNDrvs")
    8.     txtFrmSlctn.Text = rs.Fields("dbFrm")
    9.     txtBrngSlctn.Text = rs.Fields("dbBrngs")
    10.     txtChnSlctn.Text = rs.Fields("dbChn")
    11.     txtSprcktSlctn.Text = rs.Fields("dbSprckts")
    12.     txtClntChnSlctn.Text = rs.Fields("dbClntChn")
    13.     txtMDSlctn.Text = rs.Fields("dbMnDrvHP")
    14.     txtGrmtrSlctn.Text = rs.Fields("dbGrMtrBrnd")
    15.     txtHrdwrSlctn.Text = rs.Fields("dbHrdwr")

    to


    VB Code:
    1. Private Sub cmdUpdate_Click()
    2.  
    3. rs.Fields("dbCstmr") = txtCstmr.Text
    4. rs.Fields("dbDt") = txtDate.Text
    5. rs.Fields("dbDDt") = txtDueDate.Text
    6. ' etc, etc
    7.  
    8. 'after assigning it all, then do an rs.update
    9. rs.Update
    10.  
    11. End Sub



    OR you could go the more efficient way and

    VB Code:
    1. Private Sub cmdUpdate_Click()
    2.  
    3. Dim strsqlupdate As String
    4. strsqlupdate = "UPDATE tablename SET dbCstmr = '" & txtCstmr.Text & "', dbDt = '" & txtDate.Text & "', dbDDt = '" & txtDueDate.Text & ", and so on and so forth;"
    5.  
    6. cn.Execute strsqlupdate
    7. 'then close and reopen the recordset, and refill the form
    8.  
    9. End Sub

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Looking at the form, I *think* that adding directly to the form would be a little confusing for the user. It is to me at least because I can't understand what I want with a "scrubber" and "squeegee". I would suggest a new smaller form open up, and getting the user to enter values there. These values can be saved to a public variable in the original form

    After that,

    VB Code:
    1. Private Sub cmdAdd_Click()
    2.  
    3. Dim strsqladd As String
    4. strsqladd = "INSERT INTO tablename(field1, field2, field3....) VALUES('" & txtCstmr.Text & "','" & txtDate.Text & "','" & txtDueDate.Text & "',............................"
    5. cn.Execute strsqladd
    6. 'then close and reopen the recordset, and refill the form
    7.  
    8. End Sub



    Deleting would be easier. I'm assuming you have a primary key in your table at least.

    VB Code:
    1. strsqldelete = "DELETE FROM tablename WHERE primarykeyfield = '" & objrs.fields("primarykeyfield") & "';"
    2. cn.Execute strsqldelete
    3. 'then close and reopen the recordset, and refill the form



    HTH

  17. #17

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    ok, couple of things...
    'then close and reopen the recordset, and refill the form
    open it back up to the current record?
    I was only using the textboxes under the options for me to see if the option group code was working for me (I am going to remove them). Would you look at the option group function?
    VB Code:
    1. Public Sub CtrlStOptn(ctrl As Control, TagID As String)
    2. Dim Cntrl
    3.     On Error Resume Next
    4.    
    5.     For Each Cntrl In ctrl.Parent
    6.         With Cntrl
    7.             If .hwnd <> ctrl.hwnd And .Tag = TagID Then .Value = False
    8.         End With
    9.     Next Cntrl
    10. End Sub
    11.  
    12. Private Sub optFrmEpxy_Click()
    13.     If optFrmEpxy.Value = True Then CtrlStOptn optFrmEpxy, optFrmEpxy.Tag
    14.     txtFrmSlctn.Text = "Epoxy"
    15. End Sub
    16.  
    17. Private Sub optFrmSS_Click()
    18.     If optFrmSS.Value = True Then CtrlStOptn optFrmSS, optFrmSS.Tag
    19.     txtFrmSlctn.Text = "Stainless Steel"
    20. End Sub
    Is the CtrlStOptn necessary?
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  18. #18
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Beengie

    open it back up to the current record?
    After a refresh and update, yeah. You can save the bookmark to a variable, and move to that bookmark value after the update/refresh is complete.

    For adding, you can move to the newest record, considering you know in which place it will apear in the browsing order on the form.

    For delete, move to bookmark minus 1.




    I was only using the textboxes under the options for me to see if the option group code was working for me (I am going to remove them). Would you look at the option group function?
    VB Code:
    1. Public Sub CtrlStOptn(ctrl As Control, TagID As String)
    2. Dim Cntrl
    3.     On Error Resume Next
    4.    
    5.     For Each Cntrl In ctrl.Parent
    6.         With Cntrl
    7.             If .hwnd <> ctrl.hwnd And .Tag = TagID Then .Value = False
    8.         End With
    9.     Next Cntrl
    10. End Sub
    11.  
    12. Private Sub optFrmEpxy_Click()
    13.     If optFrmEpxy.Value = True Then CtrlStOptn optFrmEpxy, optFrmEpxy.Tag
    14.     txtFrmSlctn.Text = "Epoxy"
    15. End Sub
    16.  
    17. Private Sub optFrmSS_Click()
    18.     If optFrmSS.Value = True Then CtrlStOptn optFrmSS, optFrmSS.Tag
    19.     txtFrmSlctn.Text = "Stainless Steel"
    20. End Sub
    Is the CtrlStOptn necessary?
    What are you doing here? Don't you think it's a little inefficient that CtrlStOptn runs about 50 times each time I click a radio button?

    All you need in the frames are your option boxes, and the option box will get selected "as you click"

    Tell me if your CtrlStOptn accomplishes something else!

  19. #19

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    I looked for some optiongroup codes on planet source code, and that is what I found. I believe that is what I would need if I didn't use an option frame for the buttons.

    what's the best way for vbYesNo handling?

    btw...

    Thanksforallyouhelp!!
    Last edited by Beengie; Dec 2nd, 2003 at 03:06 AM.
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Like this:

    VB Code:
    1. Dim lret As Long
    2. lret = MsgBox("Are you sure?", vbYesNo, "CONFIRMATION")
    3.  
    4. If lret = vbYes Then
    5. 'do something
    6. 'delete the ****er!
    7.  
    8. Else
    9. 'do something else
    10. End If

    HTH

  21. #21

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    having problems with the delete
    VB Code:
    1. Private Sub cmdDelete_Click()
    2.     Dim strsqldelete As String
    3.     Select Case MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Record")
    4.     Case vbYes
    5.     strsqldelete = "DELETE FROM tblBrushBed WHERE intbbID = '" & rs.Fields("bbID") & "';"
    6.     cn.Execute strsqldelete
    7.     rs.Close
    8.     rs.Open "SELECT * from tblBrushBed", cn, adOpenDynamic, adLockPessimistic
    9.     FillFields
    10.     Case vbNo
    11.     'nothing to do
    12.    End Select
    13.    
    14. End Sub
    I declared the variable intbbID as an integer in the form.
    It highlights cn.Execute strsqldelete
    PS. I like the frog better
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  22. #22
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. Private Sub cmdDelete_Click()
    2.     Dim strsqldelete As String
    3.     Select Case MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Record")
    4.     Case vbYes
    5.     strsqldelete = "DELETE FROM tblBrushBed WHERE intbbID = " & rs.Fields("bbID") & ";"
    6.     cn.Execute strsqldelete
    7.     rs.Close
    8.     rs.Open "SELECT * from tblBrushBed", cn, adOpenDynamic, adLockPessimistic
    9.     FillFields
    10.     Case vbNo
    11.     'nothing to do
    12.    End Select
    13.    
    14. End Sub


    Try that.

    The reason you were having a problem is because (my guess) that intbbID is a numeric field. Whenever putting variables into numeric fields, you need not have the single quote (') in there. For textual fields, you should have it in there.

  23. #23
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Beengie

    PS. I like the frog better
    Me too, but my PR agent told me to go for a temporary makeover in order to retain smoker-clients.

  24. #24

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    same problem...
    I even tried delaring the intbbID to strbbID as a string...
    I put the single quotes back in for that...
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  25. #25
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I just checked your database.

    It's bbID not, intbbID

    VB Code:
    1. Private Sub cmdDelete_Click()
    2.     Dim strsqldelete As String
    3.     Select Case MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Record")
    4.     Case vbYes
    5.     strsqldelete = "DELETE FROM tblBrushBed WHERE bbID = " & rs.Fields("bbID") & ";"
    6.     cn.Execute strsqldelete
    7.     rs.Close
    8.     rs.Open "SELECT * from tblBrushBed", cn, adOpenDynamic, adLockPessimistic
    9.     FillFields
    10.     Case vbNo
    11.     'nothing to do
    12.    End Select
    13.    
    14. End Sub

    *applies more makeup*

  26. #26

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    ahh, I see...

    I needed to switch the code you posted from rs.Fields("bbID") to intbbID.

    I am tired and going to turn in for the evening.

    I sure appreciate the help
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  27. #27
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    No probs.

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