Solved

Object Variable or With Block Variable Not Set Error

Posted on 2009-05-05
4
853 Views
Last Modified: 2013-11-28
I  will appreciate if I could get an assistance in resolving the error below.

Run-Time Error "91" error
"Object Variable or With Block Variable Not Set not set"
Public Sub DeleteRenumber()

 

    Dim rs As DAO.Recordset

    Dim cbo As String

    Dim i As Integer

    Dim bLoop As Boolean

    Dim sPrefix As String

    Dim sSql As String

 

On Error GoTo Err_cmdDelete_Click

 

    bLoop = True

     

    sPrefix = "XW-" & rs!TestType & "-" & rs!CTypeID & "-" & rs!BNo & "-" & rs!LNo & "-" & rs!STypeID & "-"

    'Find next number from one about to be deleted

    i = Val(Mid$(Me.FDID, 2)) + 1

      

    'Now update existing records

    Set rs = Me.RecordsetClone

 

    'Find first next highest number

    sSql = "FDID = '" & sPrefix & Format(i, "00") & "'"

    Debug.Print "Looking for", sSql

    rs.FindFirst sSql

    Do While bLoop

 

        'If no records found, end loop

        If rs.NoMatch = True Then

            bLoop = False

        Else

 

            'Decrement number

            Debug.Print "Updating ID", rs!SID

            

            rs.Edit

            rs!FDID = sPrefix & Format(i - 1, "00")

            rs.Update

 

            'Find next highest

            i = i + 1

            sSql = "FDID = '" & sPrefix & Format(i, "00") & "'"

            Debug.Print "Finding next", sSql

            rs.FindNext "FDID = '" & sPrefix & Format(i, "00") & "'"

        End If

    Loop

 

    'Closedown

    rs.Close

    Set rs = Nothing

 

    Me.Requery

    

Exit_cmdDelete_Click:

    Exit Sub

 

Err_cmdDelete_Click:

    MsgBox Err.Description

    Resume Exit_cmdDelete_Click

 

End Sub

Open in new window

0
Comment
Question by:billcute
  • 2
4 Comments
 
LVL 84
Comment Utility
Can you determine the line where this occurs? Set a breakpoint at the beginning of the code, then run it and "walk" through it to find the offending line.

However, typically you should check for a NoMatch or .EOF when using FindFirst. If your code doesn't find anything, the rs variable would not be "set", and you would get this error:

rs.FindFirst sSql

If rs.NoMatch Then
  Msgbox "No Record Found"
  Exit Sub
Else
    Do While bLoop
    etc etc etc
End If
0
 
LVL 84
Comment Utility
Sorry, just saw where you ARE using NoMatch ... not sure how that one slipped past.

So, again: Can you determine the offending line?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
Comment Utility
It may be down to the usage of rs! before it has been initialised

You got this line

    sPrefix = "XW-" & rs!TestType & "-" & rs!CTypeID & "-" & rs!BNo & "-" & rs!LNo & "-" & rs!STypeID & "-"


then you got

    Set rs = Me.RecordsetClone


Should be the other way round.
0
 
LVL 4

Author Comment

by:billcute
Comment Utility
sorry...LSMConsulting

rockiroads suggestion resolved the error
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now