Solved

Object variable or With block variable not set error

Posted on 2003-10-22
7
70,323 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
Industry Leaders: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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 83
Microsoft Access combo box help 2 52
Automatic Email Reminder 4 71
VBA: copy range dynamically based on config sheet v2 3 55
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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