473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Access 2000 - error "the expression you entered refers to an object that is closed"

5
In Access 2000 I have a form with a tab control with 3 tabs. I have a button that is supposed to check if each question on the form has been completed. The code that is under this button is below. It works for the questions on the first 2 tabs but when it gets to the questions on the 3rd tab I get the following error message "The expression you entered refers to an object that is closed or doesn't exist".

This code does work properly on another form that only has 1 tab but also fails on a third form that has 5 tabs (it fails on the 5th tab)/

I am pretty new to adding VB to Access forms so any help would be appreciated.

Here is the code
Private Sub Command199_Click()
Dim ctl As Control
On Error GoTo Err_command199
For Each ctl In Me.Controls
If IsNull(ctl) Then
MsgBox "You must enter a value into " & ctl.Controls(0).Caption & "."
ctl.SetFocus
Cancel = True
Exit Sub
End If
Next

Exit_command199:
Exit Sub

Err_command199:
MsgBox Err.Description
'MsgBox "All the data have been entered"
Resume Exit_command199
End Sub
Jul 31 '07 #1
6 6563
weston
5
I have been working more on solving this problem and have some additional information.

On the bottom of each page I have a calculate command button that calculates a score. I have zeroed in that the problem occurs at the bottom of page 2. The code works through all the fields properly until the bottom of page 2 before the calculate button is clicked. I then get the error " The expression you entered refers to an object that is closed or doesn't exist". When I click the calculate button the error message changes to "Object doesn't support this property or method". Then if I click the first field on page 3 with a valid answer the code works properly with the rest of the fields on page 3.

I wonder if there is some control there that I can't see but I am not sure how to look for it.
Thanks again for any help.
Jul 31 '07 #2
ADezii
8,834 Expert 8TB
In Access 2000 I have a form with a tab control with 3 tabs. I have a button that is supposed to check if each question on the form has been completed. The code that is under this button is below. It works for the questions on the first 2 tabs but when it gets to the questions on the 3rd tab I get the following error message "The expression you entered refers to an object that is closed or doesn't exist".

This code does work properly on another form that only has 1 tab but also fails on a third form that has 5 tabs (it fails on the 5th tab)/

I am pretty new to adding VB to Access forms so any help would be appreciated.

Here is the code
Private Sub Command199_Click()
Dim ctl As Control
On Error GoTo Err_command199
For Each ctl In Me.Controls
If IsNull(ctl) Then
MsgBox "You must enter a value into " & ctl.Controls(0).Caption & "."
ctl.SetFocus
Cancel = True
Exit Sub
End If
Next

Exit_command199:
Exit Sub

Err_command199:
MsgBox Err.Description
'MsgBox "All the data have been entered"
Resume Exit_command199
End Sub
Cancel = True
If you are trying to Cancel the Update of a Record from within the Click() Event of a Command Button, you cannot set Cancel = True.
Jul 31 '07 #3
weston
5
I have kept working on the problem and have found the solutiion I think.

The text box that held the result of the calculation from the calculate button was empty. Once I put a default missing value in that field everything works now.
Jul 31 '07 #4
missinglinq
3,532 Expert 2GB
As ADezii said, you can only include Cancel = True in subs such as BeforeUpdate events. You can tell whether or not this code can be used by the Cancel As Integer as in here:
Private Sub YourField_BeforeUpdate(Cancel As Integer).

"Object doesn't support this property or method" is probably being caused because you're not just checking controls such as textboxes or comboboxes for nulls and setting focus to them, you're checking all controls, including labels, and trying to set focus to them if they're null. Since labels (among other controls) cannot receive focus, the don't support this property or method, and hence the error. You need to correct these first. Also, you have your code set up so that, in the middle of your loop, if a control is null, you exit the sub! That's not right! You need to correct the problem, then continue the loop.

Let's start by replacing
Expand|Select|Wrap|Line Numbers
  1. For Each ctl In Me.Controls
  2.  If IsNull(ctl) Then
  3.  MsgBox "You must enter a value into " & ctl.Controls(0).Caption & "."      ctl.SetFocus
  4. Cancel = True
  5. Exit Sub
  6.  End If
  7. Next
With this
Expand|Select|Wrap|Line Numbers
  1. For Each ctl In Me.Controls
  2.  If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
  3.   If IsNull(ctl) Then
  4.   MsgBox "You must enter a value into " & ctl.Controls(0).Caption & "."
  5.   ctl.SetFocus
  6.   End If
  7. End If
  8. Next
Jul 31 '07 #5
ADezii
8,834 Expert 8TB
I have kept working on the problem and have found the solutiion I think.

The text box that held the result of the calculation from the calculate button was empty. Once I put a default missing value in that field everything works now.
ling had some excellant pointers and you should follow them. There is something else that will help in similar type situations. Anytime you may be referencing Properties/Methods of Controls as a whole, without regards to what Properties or Methods may be applicable to them, you should use
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
at the beginning of the code segment.
Jul 31 '07 #6
weston
5
Thanks for the help. I will try what you have suggested.
Aug 1 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michelle | last post by:
Hello all, I recently inherited a SQL 7.0 Server db accessed by a 2000 Access interface. When I try to open "Shipping Check Out" I am greeted with the following: The expression On Load you...
4
by: David Cho | last post by:
Hi, this is just plain strange. This is my code. HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.yahoo.com"); request.Method = "POST"; request.ContentType =...
1
by: Elie | last post by:
Hello I get this error when the code runs from the server as an .asp page or from a compiled dll. But When I log onto the server and run a vb program that executes the same code, it works...
2
by: lucy | last post by:
Hi, I use ADOX to create a Access database programmatically from my asp.net application and save ".mdb" file to a temp folder under my project foler on the web server. After database is created...
6
by: nick cheng | last post by:
i want use vb to write a program. it is used to record the "IE history", i am using WinXP,when i try to access the history directory use this path "C:\Documents and Settings\Nick\Local...
0
by: lpinho | last post by:
Hi There, I've generated a C# file from a wsdl file using wsdl.exe utility. Then I created a console application and made a call to the method generated, first I got the error: "The request...
2
by: Anders | last post by:
Hi Im trying to develop a C# application which interacts with a Fingerprint scanner. The appliaction is going to run in the background (and as trayicon). When my applicatons catches an...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
1
by: LiveCycle | last post by:
Hi, I've got a longstanding project that's been working fine for about a year. I was working on one of the pages, a simple download page. After making a little tweak on the page, I tried to...
4
by: Sin Jeong-hun | last post by:
I don't get the message so it's hard to debug that, but some of my clients report that they get "The underlying connection was closed unexpectedly" exception. According to this site (http://...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.