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

Determine whether a specified control exists on another form or report object?

MLH
From FormA or from the immediate window, what can I run to
determine if a specified control (say, "MyComboBox") exists on
FormB (or ReportB)? We could narrow it down, specifying that
FormB (or ReportB) would be opened in design view at the time
of the inquiry.
Nov 13 '05 #1
4 3419
On Sun, 10 Jul 2005 23:09:01 -0400, MLH <CR**@NorthState.net> wrote:

No need for design view. Just walk the form's Controls collection.
-Tom.

From FormA or from the immediate window, what can I run to
determine if a specified control (say, "MyComboBox") exists on
FormB (or ReportB)? We could narrow it down, specifying that
FormB (or ReportB) would be opened in design view at the time
of the inquiry.


Nov 13 '05 #2
MLH
Thanks. Something like this, right?

Private Sub FindCtrlBttn_Click()
'************************************************* ************************
' Purpose: Walk the Controls Collection for user-specified form,
looking
' for a user-specified control. The controls collection is a form's
de-
' fault collection.
'************************************************* ************************
On Error GoTo FindCtrlBttn_ClickError
Dim ThisForm As String
ThisForm = Me.Name
Dim i As Integer, intHowmany As Integer, WhichForm As String,
WhichCtrl As String, Xcoord As Single, Ycoord As Single

Msg = "Enter form name." ' Set prompt.
Title = "Form Name?" ' Set title.
Defvalue = "frmListThings" ' Set default return
value.
WhichForm = InputBox$(Msg, Title, Defvalue) ' Get user input.
Msg = "Enter control name." ' Set prompt.
Title = "Control Name?" ' Set title.
Defvalue = "frmListThings1" ' Set default return
value.
WhichCtrl = InputBox$(Msg, Title, Defvalue) ' Get user input.
If WhichForm = "" Or WhichCtrl = "" Then Exit Sub
For i = 0 To Forms(WhichForm).Count - 1
intHowmany = intHowmany + 1
If Forms(WhichForm)(i).Name = WhichCtrl Then
FoundIt = True 'Format(5459.4, "##,##0.00")
Xcoord = Format(Forms(WhichForm)(i).left / 1440, "00.000")
Ycoord = Format(Forms(WhichForm)(i).top / 1440, "00.000")
End If
Next i
If FoundIt = True Then
Msg = "Yes, " & WhichForm & " has a control named " &
WhichCtrl & "."
Msg = Msg & CRLF & CRLF & "(x,y) = (" & CStr(Xcoord) & "," &
CStr(Ycoord) & ")"
MsgBox Msg, 64, "Found Control - " & MyApp$ & ", rev. " &
MY_VERSION$
Else
Msg = "No, " & WhichForm & " has no control named " &
WhichCtrl & "."
MsgBox Msg, 64, "Control Not Found - " & MyApp$ & ", rev. " &
MY_VERSION$
End If

ExitFindCtrlBttn_Click:
Exit Sub

FindCtrlBttn_ClickError:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
FindCtrlBttn_Click, CBF on " & ThisForm & "."
k = CRLF & CRLF & "Error # " & Trim$(Str$(Err)) & ": " & Quote &
Error$ & Quote
Message3 = r & k
MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " &
MY_VERSION$
Resume ExitFindCtrlBttn_Click

End Sub

Nov 13 '05 #3
On Mon, 11 Jul 2005 01:13:11 -0400, MLH <CR**@NorthState.net> wrote:

Yes, except I would make it a function in a module (taking 2
arguments), so it can become part of a standard library of functions.

-Tom.
Thanks. Something like this, right?

Private Sub FindCtrlBttn_Click()
'************************************************ *************************
' Purpose: Walk the Controls Collection for user-specified form,
looking
' for a user-specified control. The controls collection is a form's
de-
' fault collection.
'************************************************ *************************
On Error GoTo FindCtrlBttn_ClickError
Dim ThisForm As String
ThisForm = Me.Name
Dim i As Integer, intHowmany As Integer, WhichForm As String,
WhichCtrl As String, Xcoord As Single, Ycoord As Single

Msg = "Enter form name." ' Set prompt.
Title = "Form Name?" ' Set title.
Defvalue = "frmListThings" ' Set default return
value.
WhichForm = InputBox$(Msg, Title, Defvalue) ' Get user input.
Msg = "Enter control name." ' Set prompt.
Title = "Control Name?" ' Set title.
Defvalue = "frmListThings1" ' Set default return
value.
WhichCtrl = InputBox$(Msg, Title, Defvalue) ' Get user input.
If WhichForm = "" Or WhichCtrl = "" Then Exit Sub
For i = 0 To Forms(WhichForm).Count - 1
intHowmany = intHowmany + 1
If Forms(WhichForm)(i).Name = WhichCtrl Then
FoundIt = True 'Format(5459.4, "##,##0.00")
Xcoord = Format(Forms(WhichForm)(i).left / 1440, "00.000")
Ycoord = Format(Forms(WhichForm)(i).top / 1440, "00.000")
End If
Next i
If FoundIt = True Then
Msg = "Yes, " & WhichForm & " has a control named " &
WhichCtrl & "."
Msg = Msg & CRLF & CRLF & "(x,y) = (" & CStr(Xcoord) & "," &
CStr(Ycoord) & ")"
MsgBox Msg, 64, "Found Control - " & MyApp$ & ", rev. " &
MY_VERSION$
Else
Msg = "No, " & WhichForm & " has no control named " &
WhichCtrl & "."
MsgBox Msg, 64, "Control Not Found - " & MyApp$ & ", rev. " &
MY_VERSION$
End If

ExitFindCtrlBttn_Click:
Exit Sub

FindCtrlBttn_ClickError:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
FindCtrlBttn_Click, CBF on " & ThisForm & "."
k = CRLF & CRLF & "Error # " & Trim$(Str$(Err)) & ": " & Quote &
Error$ & Quote
Message3 = r & k
MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " &
MY_VERSION$
Resume ExitFindCtrlBttn_Click

End Sub


Nov 13 '05 #4
MLH
An excellent suggestion, Tom. Thanks a lot.
BTW, Tom, do you have any ideas regarding
my earlier post regarding "=GetMyCriteria()"?
That one has been a real stickler for me.
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: JT | last post by:
is there a way to determine if a form object actually exists? if i use the following syntax: varTextField = Request.Form("txtFormField") then varTextField = "" which gives the same result...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
1
by: Ron Holmes | last post by:
I posted this question on the Crystal Reports Support site and I am still waiting for an answer. Using Crystal Reports 9.0 Developer Full edition: My Crystal report .RPT file has a Picture box...
4
by: Oldhandandy | last post by:
Since upgrading to .Net 2003, when I run report reports within an application using CrystalReportViewer, I'm getting the error "Specified Cast is not Valid". A value is being passed into the report.
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
7
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
8
by: Arpan | last post by:
Consider the following code snippet (my main intention is to display the current time in a Label control as & when this ASPX page is accessed/refreshed): <script runat="server"> Class Clock...
9
by: Mark Berry | last post by:
Hi, How can I determine whether an object is derived from another object? My specific example is that I have a CustomError class with several specific error types that derive from it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.