Run Time Error 91: Object variable or With Block variable not set 
Author Message
 Run Time Error 91: Object variable or With Block variable not set

MY BACKGROUND:
I am very new with classes. This will be my first attempt at them. I am
using VB5 on WIN95

APP BACKGROUND:
I am creating an application (for our office) which will open our yearly
customer database. I also want to allow the app to open last year's
database (for research), and next years database (to set it up ahead of
time). Basically you could have several databases open at once. I am
using an MDI Parent form and the databases will be displayed on an
msFlexGrid inside MDI child forms. Before opening a database, I check to
see if it is already opened, and prompt the user to revert to it or not.
I also use a class to keep track of each database as an object.

PROBLEM ENCOUNTERED:
I can open the first 2 databases no problem. But when I open the 3rd
database I get the error:  Run Time Error 91: Object variable or With
Block variable not set

CODE:

    diaM.ShowOpen                '--- Display CommonDialog to open file

    '--- Check if file exists
    If (Dir(diaM.filename) = "") Then
        M = MsgBox("Invalid filename", 48)
        Exit Sub
    End If

    '--- Check if file is already open here
    Debug.Print "Objects:"; O
    For I = 1 To O
        Debug.Print "I="; I
        If (N(I).sFILENAME = diaM.filename) Then        '--- ERROR HERE
with (I = 1)
            M = MsgBox("Do you want to revert to previously opened
file?", 36)
            If (M = 6) Then N(I).sSHOW: Exit Sub
        End If
    Next

    '--- Create new Form Object                 '
    O = O + 1
    ReDim N(1 To O) As clsDATA
    Set N(O) = New clsDATA
    N(O).sOPEN (diaM.filename)

Thanks for all info.
Guy Doucet



Sat, 24 Feb 2001 03:00:00 GMT  
 Run Time Error 91: Object variable or With Block variable not set
It looks like you are mis-using the "With" keyword.  Just set i=1 without
the With.  The "With" statement is used when referencing a user defined type
so that the structure name does not need to be referenced each time.
Example

Type Address
  FirstName as String
  LastName as String
end Type

Dim MyAddress as Address

'Using the With statement you can then write the code...
With MyAddress
  .FirstName = Bill
  .LastName = Clinton
end With

'//for large Types this does save time and is supposed to reduce access
time.
'//Same code without "With"
MyAddress.FirstName = Bill
MyAddress.LastName = Clinton

Quote:

> MY BACKGROUND:
> I am very new with classes. This will be my first attempt at them. I am
> using VB5 on WIN95

> APP BACKGROUND:
> I am creating an application (for our office) which will open our yearly
> customer database. I also want to allow the app to open last year's
> database (for research), and next years database (to set it up ahead of
> time). Basically you could have several databases open at once. I am
> using an MDI Parent form and the databases will be displayed on an
> msFlexGrid inside MDI child forms. Before opening a database, I check to
> see if it is already opened, and prompt the user to revert to it or not.
> I also use a class to keep track of each database as an object.

> PROBLEM ENCOUNTERED:
> I can open the first 2 databases no problem. But when I open the 3rd
> database I get the error:  Run Time Error 91: Object variable or With
> Block variable not set

> CODE:

>     diaM.ShowOpen                '--- Display CommonDialog to open file

>     '--- Check if file exists
>     If (Dir(diaM.filename) = "") Then
>         M = MsgBox("Invalid filename", 48)
>         Exit Sub
>     End If

>     '--- Check if file is already open here
>     Debug.Print "Objects:"; O
>     For I = 1 To O
>         Debug.Print "I="; I
>         If (N(I).sFILENAME = diaM.filename) Then        '--- ERROR HERE
> with (I = 1)
>             M = MsgBox("Do you want to revert to previously opened
> file?", 36)
>             If (M = 6) Then N(I).sSHOW: Exit Sub
>         End If
>     Next

>     '--- Create new Form Object                 '
>     O = O + 1
>     ReDim N(1 To O) As clsDATA
>     Set N(O) = New clsDATA
>     N(O).sOPEN (diaM.filename)

> Thanks for all info.
> Guy Doucet



Sat, 24 Feb 2001 03:00:00 GMT  
 Run Time Error 91: Object variable or With Block variable not set
the code doesn't appear as it should. in my previous posting.

the line that says "with (I = 1)" is part of the remark of the previous
line. I just wanted to say that the error happened when the variable ( I )
of the FOR-NEXT loop was at ( 1 ).

Sorry for the confusion.
Guy Doucet



Sat, 24 Feb 2001 03:00:00 GMT  
 Run Time Error 91: Object variable or With Block variable not set
I forgot to use the PRESERVE keyword when REDIMing my array, sorry for the
trouble.

Guy Doucet a crit:

Quote:
> MY BACKGROUND:
> I am very new with classes. This will be my first attempt at them. I am
> using VB5 on WIN95

> APP BACKGROUND:
> I am creating an application (for our office) which will open our yearly
> customer database. I also want to allow the app to open last year's
> database (for research), and next years database (to set it up ahead of
> time). Basically you could have several databases open at once. I am
> using an MDI Parent form and the databases will be displayed on an
> msFlexGrid inside MDI child forms. Before opening a database, I check to
> see if it is already opened, and prompt the user to revert to it or not.
> I also use a class to keep track of each database as an object.

> PROBLEM ENCOUNTERED:
> I can open the first 2 databases no problem. But when I open the 3rd
> database I get the error:  Run Time Error 91: Object variable or With
> Block variable not set

> CODE:

>     diaM.ShowOpen                '--- Display CommonDialog to open file

>     '--- Check if file exists
>     If (Dir(diaM.filename) = "") Then
>         M = MsgBox("Invalid filename", 48)
>         Exit Sub
>     End If

>     '--- Check if file is already open here
>     Debug.Print "Objects:"; O
>     For I = 1 To O
>         Debug.Print "I="; I
>         If (N(I).sFILENAME = diaM.filename) Then        '--- ERROR HERE
> with (I = 1)
>             M = MsgBox("Do you want to revert to previously opened
> file?", 36)
>             If (M = 6) Then N(I).sSHOW: Exit Sub
>         End If
>     Next

>     '--- Create new Form Object                 '
>     O = O + 1
>     ReDim N(1 To O) As clsDATA
>     Set N(O) = New clsDATA
>     N(O).sOPEN (diaM.filename)

> Thanks for all info.
> Guy Doucet



Sun, 25 Feb 2001 03:00:00 GMT  
 Run Time Error 91: Object variable or With Block variable not set
Maybe try:

Redim Preserve ReDim N(1 To O)

(Redim without Preserve will reset all of the objects in the array to
Nothing)

Hope this helps.

Quote:

> > PROBLEM ENCOUNTERED:
> > I can open the first 2 databases no problem. But when I open the 3rd
> > database I get the error:  Run Time Error 91: Object variable or With
> > Block variable not set

> > CODE:

.
.
.

Quote:
> >     '--- Create new Form Object                 '
> >     O = O + 1
> >     ReDim N(1 To O) As clsDATA
> >     Set N(O) = New clsDATA
> >     N(O).sOPEN (diaM.filename)

--
      *=*=*=*=*=*=*=*=*=*=*=*=*=*=*
      Brad Bowes
      phone:     (403) 295-0691

      *=*=*=*=*=*=*=*=*=*=*=*=*=*=*


Mon, 26 Feb 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Object variable or With block variable not set (Error 91)

2. error 91 Object Variable o on with block variable is not set

3. Runtime error 91/Object variable or With block variable not set problems

4. runtime error: 91 Object variable or with block variable not set

5. Object variable or With block variable not set (Error 91) Please Help

6. VB 5.0 - Error:91 Object Variable Or With Block Variable Not Set

7. Object variable or With block variable not set (Error 91)

8. Error 91 Object variable or With-Block, variable not set

9. Object Variable not set , Run Time error 91, please Help

10. Run Time Error 91: Object Variable not set.....

11. Error 91-Object or block with variable not set

12. error 91 - object or block with variable not set

 

 
Powered by phpBB® Forum Software