Solved

Object Variable or With Block Variable Not Set Error

Posted on 2009-05-05
4
859 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85
ID: 24303272
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 85
ID: 24303278
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
ID: 24303457
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
ID: 24307742
sorry...LSMConsulting

rockiroads suggestion resolved the error
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

696 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