Solved

Object variable or With block variable not set error

Posted on 2003-10-22
7
70,317 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
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

777 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