Solved

Object variable or With block variable not set error

Posted on 2003-10-22
7
70,329 Views
Last Modified: 2011-08-18
Iam Getting an error called Object variable or With block variable not set
the error number is 0091:
Below is my code:

Private Sub tmpinput_LostFocus(Index As Integer)
10         On Error GoTo ERROR
20         tmpinput(Index).BackColor = QBColor(15)
           Dim CC1, CC2, tError
30         If UCase(ActiveControl.Name) = "QUIT" Or UCase(ActiveControl.Name) = "LABEL2" Then Exit Sub
-
-
-
-
-
-

end sub

the code above goes after the if condition iam getting the error at this if condition:

If UCase(ActiveControl.Name) = "QUIT" Or UCase(ActiveControl.Name) = "LABEL2" Then Exit Sub

Please help me as soon as possible

Waiting  for ur reply,
Murali Krishna
0
Comment
Question by:murali001_paithara
[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
7 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 9597429
if you get that error then activecontrol is nothing so you lost the reference to the object somewhere before the if test
0
 

Author Comment

by:murali001_paithara
ID: 9597437
Please help me out to solve this
0
 
LVL 44

Expert Comment

by:bruintje
ID: 9597466
then post more of your code, we can't see what's happening before you go into the if statement and it looks like the object is already nothing by then
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 5

Expert Comment

by:fantasy1001
ID: 9597521
   Dim myHandler As Object
    Set myHandler = ActiveControl

Change If UCase(ActiveControl.Name) = "QUIT" Or UCase(ActiveControl.Name) = "LABEL2" Then Exit Sub TO

If UCase(myHandler.Name) = "QUIT" Or UCase(myHandler.Name) = "LABEL2" Then Exit Sub

Also one thing to notice, myHandler.Name is the name of the control. You should use myHandler.Caption instead.

Thanks & Cheers
   
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
ID: 9597553
Sorry, I was confused just now. You got the Error because the ActiveControl is nothing at the time, which mean there is not control in focus at the time.

'You can check the existence of ActiveObject first
If Not ActiveControl Is Nothing Then
        If UCase(ActiveControl.Name) = "QUIT" Or UCase(ActiveControl.Name) = "LABEL2" Then Exit Sub
End If

0
 
LVL 2

Expert Comment

by:diarmaid
ID: 9597583
I think more code is required.

1st Dont use Error as label name, ie instead of "On Error GoTo ERROR" use something like "On Error GoTo LostFocusError". Error is a keyword inside Visual Basic.

There are many reasons you will get err 91. You may have ommitted a Set statement, you may be trying to use an object that has been set to nothing, etc etc. very hard to guess without complete code.
0
 

Expert Comment

by:maphuti
ID: 11210296
Private Sub Form_Load()
 Dim Rs1 As ADODB.Recordset
   Dim txt As TextBox
    'frmCustomer.txtAccountNo = Rs1!accountno
    'frmCustomer.txtCustName = Rs1!CustName
    'frmCustomer.txtCustAddress = Rs1!CustAddress
    'frmCustomer.txtCustTelNo = Rs1!CustTelNo
    'frmCustomer.txtCustFaxNo = Rs1!CustFaxNo
    'frmCustomer.txtComments = Rs1!Comments
    'frmCustomer.txtCustBookNo = Rs1!CustBookNo
     
End Sub
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

623 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