473,382 Members | 1,545 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,382 software developers and data experts.

Test for Parent or Subform without error trapping

1,271 Expert 1GB
Is there a property or method that can be used to determine if a form has a parent or not? If I make any reference to frm.Parent it triggers an error if the form does not have a parent.

I'd like to make my subforms have a different background color than my forms (dynamically with code, not by setting properties). But I prefer to do it without triggering an error.

Thanks,

Jim
May 6 '14 #1
4 6814
zmbd
5,501 Expert Mod 4TB
Sorry, the only way I've found to do this is to error trap.
May 6 '14 #2
NeoPa
32,556 Expert Mod 16PB
Sorry Jim. The best I have is to encapsulate it in a procedure :
Expand|Select|Wrap|Line Numbers
  1. 'OnSubform() returns True if frmVar is open within a subform on another form.
  2. Public Function OnSubform(frmVar As Form) As Boolean
  3.     OnSubform = True
  4.     On Error Resume Next    'Then statement is executed on error
  5.     If Not TypeOf frmVar.Parent Is Form Then OnSubform = False
  6. End Function
May 8 '14 #3
jimatqsi
1,271 Expert 1GB
Thanks to both of you. I have reluctantly accepted that as the solution, but I remain surprised and disappointed that there is not another way.

Jim
May 8 '14 #4
zmbd
5,501 Expert Mod 4TB
OK,

This is a very common method to determine if a form is loaded:
Expand|Select|Wrap|Line Numbers
  1. If CurrentProject.AllForms("FormName").IsLoaded Then
  2.     ' DO SOMETHING
  3. End If
I do know that if the form is a subform, and not loaded as a standalone, and the parent form is opened with the subform loaded then CurrentProject.AllForms("SubFormName").IsLoaded = FALSE.

Now I use this in my subforms to check to see if the parent is opened and I cancel the open if the parent is NOT opened to keep the subforms from erroring

SO, if the code, ran as subform on_open, returns false, then we're 95% assured that the form has been opened as a subform and easy to confirm with Neopa's function or any numerous methods.

HOWEVER,

if the result is true then we know that, there is at lest one form with that name loaded as a standalone and it could be the form calling the code or one that was already open as standalone. This is the logical rub...
May 8 '14 #5

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

Similar topics

8
by: Pete | last post by:
I'm trying to improve my code so that when I open a recordset object, I can absolutely guarantee it is closed and is set = Nothing. I have read some old threads and they all say to use the...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
4
by: Michael Fay | last post by:
There have been threads in this newsgroup explaining how to tab out of a subform to the parent form -- without having to use ctrl-tab (of which users might be unaware -- and at any rate, they...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
1
by: Lindsay | last post by:
How does one perform error trapping? I'm using GdiplusStartup and want to trap the dll not found error.
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
0
by: JohnJohnUSA | last post by:
I ran the following program to retrieve entries from the windows registry on Windows XP: import win32api, win32con aReg = win32api.RegConnectRegistry(None, win32con.HKEY_CURRENT_USER) aKey =...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.