Solved

Object variable or With block variable not set error

Posted on 2003-10-22
7
70,324 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 90
Access 2013 combo box not working 3 73
Visual Studio search word table and return Cell index 8 83
Problem to line 23 79
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

736 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