Object variable or With block variable not set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gazerdood
    New Member
    • Apr 2010
    • 6

    #1

    Object variable or With block variable not set

    Hi when I click the command button to run this piece of code:

    Code:
    Private Sub recoverpass_cmd_Click()
    Dim c As String
    Dim b As String
    Dim foundflag  As Integer
    Adodc2.Recordset.MoveFirst
    Do
    b = Adodc2.Recordset.Fields!Username
    c = Adodc2.Recordset.Fields!Security
    Error in line 5: 'Adodc2.Records et.MoveFirst2'

    Run-time error '91':
    Object variable or With block variable not set


    What do I have to do to fix it? This was working before but it suddenly stopped. I am using Adodc's elsewhere but not with the same name.

    Thanks!

    PS: This is only the code up to where the errors occur, I am aware that on this it has no 'End Sub' etc, Thanks!
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    you need to declare the variable "Adodc2"

    Comment

    • Gazerdood
      New Member
      • Apr 2010
      • 6

      #3
      How do I do that?

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        oh! I misread your post - ok so I assume you have an Adodc control on your form called "Adodc2" right? ... If you're getting this error, it probably means that you need to set a reference to "Microsoft ActiveX Data Objects" in order to use that class.

        you could also try this
        Code:
        Adodc2.Refresh
        Adodc2.Recordset.MoveFirst

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          Or it may mean that the ADODC does not have a recordsource and thus is not "open"...



          Good Luck

          Comment

          Working...