Solved

Object variable or With block variable not set error

Posted on 2003-10-22
7
70,313 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
Comment Utility
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
Comment Utility
Please help me out to solve this
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
   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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now