
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